diff options
| author | Fabian Kosmale <fabian.kosmale@qt.io> | 2025-07-18 16:22:50 +0200 |
|---|---|---|
| committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2025-07-22 10:18:31 +0200 |
| commit | 8effdd97d967fbeec4f143885dcd671516383740 (patch) | |
| tree | 18b8d343916f2a3d8171cdda204fb3bc8e85640b /tools/qmljsrootgen/main.cpp | |
| parent | 61d8f8fdf39990b77611e74fffb0230e3429ca64 (diff) | |
Expose XMLHttpRequest to qmltypes
In QML, one can use XMLHttpRequest. Not so with a plain JS engine. The
reason for that lies in the fact that a JS engine did not have any
network access, because all network functionality was in the type
loader, and the type loader was coupled to the QV4::Engine.
This has changed in d2bc4a4330254c0c68a0ade51b59a71c4b67b470, but we
stil don't expose XMLHttpRequest to a plain QJSEngine.
Nevertheless, it conceptually lives in the global object, and we need to
collect information about it to enable code completion and linting.
Consequently, expose a function in QV4::Engine, which allows us to
manually trigger the registration, and call it in qmljsrootgen.
Going forward, we should arguably have a QJSEngine::Extension for
XMLHttpReuqest, after which we could remove the hack.
Note that as before, qmljsrootgen prints a few warnings, because we call
functions in contexts in which they must not be called. As before, we
ignore this for now.
As a side-effect, this adds a few more entries to the qmltypes file for
new entries on the global Qt object.
Task-number: QTBUG-137075
Pick-to: 6.10
Change-Id: I21e9d62bf075e8d4356db8f357502feb927717e7
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Diffstat (limited to 'tools/qmljsrootgen/main.cpp')
| -rw-r--r-- | tools/qmljsrootgen/main.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/tools/qmljsrootgen/main.cpp b/tools/qmljsrootgen/main.cpp index acd375144e..02be0311a3 100644 --- a/tools/qmljsrootgen/main.cpp +++ b/tools/qmljsrootgen/main.cpp @@ -347,6 +347,12 @@ int main(int argc, char *argv[]) QJSEngine engine; engine.installExtensions(QJSEngine::AllExtensions); + // ugly hack: yes, there's no way to have XmlHttpRequest in plain JS, but we'll add another extension later. + // We need this approach to have a solution to get XMLHttpRequest into qmltypes for Qt < 6.11 +#if QT_CONFIG(qml_xml_http_request) + engine.handle()->setupXmlHttpRequestExtension(); +#endif + QJsonArray classesArray; State seen; |
