For context, I'm trying to use XMLHttpRequest in QML to fetch some data from a site. I will then parse that JSON and do whatever is needed, but that's not the issue. Specifically, the issue is that qmlls keeps reporting the [unqualified] error at any mention of XMLHttpRequest. The app and qmllint report no errors at all, I just want qmlls to stop returning that error.
I've tried importing QtQuick 2.15 and QtQml 2.15, but they don't change anything. How do I make qmlls properly detect XMLHttpRequest?
Note: I use the Codium extension "Qt Qml" from Qt, which uses /usr/bin/qmlls6.
A minimal example:
import QtQml 2.15
import QtQuick 2.15
Rectangle {
function fetch() {
var request = new XMLHttpRequest()
request.open('GET', 'https://example.org', true);
request.onreadystatechange = function() {
if (request.readyState === XMLHttpRequest.DONE) {
if (request.status && request.status === 200) {
console.log(request.responseText)
} else {
console.log("HTTP:" + request.status + "\nstatustext:" + request.statusText)
}
}
}
request.send()
}
Component.onCompleted: {
fetch()
}
}
In this piece of code, XMLHttpRequest() gets underlined with yellow, and hovering over it shows "Unqualified access [unqualified]".
XMLHttpRequest works just fine, returning 200 OK for valid sites.
Oddly enough, using it exactly as the example in the Qt docs works just fine (importing a JS file with the function and calling it from within QML), as suggeested by @smr . Why does this happen? Is this how developers normally use XMLHttpRequest?
request.statusreturn 200? Isrequest.responseTextcorrect? If yes, the issue is your external component and notXMLHttpRequest. If no check the server with some tool like Postman, perhaps its response is incorrect.Unqualified accesswarning. If that’s the warning you’re seeing, edit your post to include the exact warning text so readers know what to fix.