This might be obvious to Javascript programmers, but this is a problem for fresh JavaScript programmers.
The code opens txt file(size is 2MB, but that doesn’t matter – might be even bigger – and can be local and can be over network)
if run from QML this code runs great:
import "js/Parser.js" as Parser
...
onAccepted:
{
var request = new XMLHttpRequest()
request.open('GET', fileUrl)
request.onreadystatechange = function(event) {
if (request.readyState == XMLHttpRequest.DONE)
{
txtHello.text = Parser.parseFile(request.responseText)
}
}
request.send()
}
when I create function with duplicate code in Parser.js file:
function parseFileHelper(fileUrl)
{
var request = new XMLHttpRequest()
var txt = "";
request.open('GET', fileUrl)
request.onreadystatechange = function(event) {
if (request.readyState == XMLHttpRequest.DONE)
{
txt = parseFile(request.responseText)
}
}
request.send()
return txt
}
it fires errors:
QSslSocket: cannot resolve TLSv1_1_client_method
QSslSocket: cannot resolve TLSv1_2_client_method
QSslSocket: cannot resolve TLSv1_1_server_method
QSslSocket: cannot resolve TLSv1_2_server_method
QSslSocket: cannot resolve SSL_select_next_proto
QSslSocket: cannot resolve SSL_CTX_set_next_proto_select_cb
QSslSocket: cannot resolve SSL_get0_next_proto_negotiated
What am I doing wrong? The only change is that I want to store all extra JavaScript code in external file – in one place. If there was any information in google or Qt documentation(JavaScript documentation is skipped as it provides too wide information, that doesn’t guaranteed to run on QML).
The problem is that for beauty of code and practical reasons it would be better to keep all XMLHttpRequest usage in external .js file(ok, and getting to understand why there is that QSslSocket error might be a great plus as well) – the problem there is that there will be opened 3-5 files in one session and writing them all in QML is too much of code – all of them can be opened with one function – the different part is with parsing files and that is not a problem to call from external JavaScript file – why should it be with calling XMLHttpRequest?
↧