aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlbuiltinfunctions_p.h
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2022-03-31 16:28:24 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2022-11-28 17:10:07 +0100
commit6656567a4085e3d6de01226fb7b1ec16ee7ba08c (patch)
tree9d021e9f3c17d468dcc6bc1be52c0e595019a662 /src/qml/qml/qqmlbuiltinfunctions_p.h
parent6cd8d209ec472a658a330f25b84f92cd61e0d4cf (diff)
Introduce type based overload of Qt.createComponent
Add type based createComponent overloads based on QQmlComponent::loadFromModule. They provide a way to instantiate a component by its type, specified by a URI and typename pair. This enables creating Components for inline component types and C++ only types. Support for directly passing the type is deferred to a later commit, as it needs some care to work together with the compiler. As the string based overload matches a mistaken call to the URL based createComponent with parent and mode swapped (due to anything being convertible to string), we add a check to detect this specific error case and give a helpful error message. [ChangeLog][QtQml] Qt.createComponent now supports creating a Component from its module and type name (passed as strings). Task-number: QTBUG-97156 Fixes: QTBUG-26278 Change-Id: I89e7430fe02d52f57230bfa1b0bfbcbfd0ead4b7 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlbuiltinfunctions_p.h')
-rw-r--r--src/qml/qml/qqmlbuiltinfunctions_p.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlbuiltinfunctions_p.h b/src/qml/qml/qqmlbuiltinfunctions_p.h
index b961fe6e56..2739524516 100644
--- a/src/qml/qml/qqmlbuiltinfunctions_p.h
+++ b/src/qml/qml/qqmlbuiltinfunctions_p.h
@@ -131,6 +131,12 @@ public:
const QUrl &url, QQmlComponent::CompilationMode mode = QQmlComponent::PreferSynchronous,
QObject *parent = nullptr) const;
+ Q_INVOKABLE QQmlComponent *createComponent(const QString &moduleUri,
+ const QString &typeName, QObject *parent) const;
+ Q_INVOKABLE QQmlComponent *createComponent(const QString &moduleUri, const QString &typeName,
+ QQmlComponent::CompilationMode mode = QQmlComponent::PreferSynchronous,
+ QObject *parent = nullptr) const;
+
Q_INVOKABLE QJSValue binding(const QJSValue &function) const;
Q_INVOKABLE void callLater(QQmlV4Function *args);
@@ -156,6 +162,12 @@ private:
QJSEngine *jsEngine() const { return m_engine->jsEngine(); }
QV4::ExecutionEngine *v4Engine() const { return m_engine; }
+ struct Contexts {
+ QQmlRefPointer<QQmlContextData> context;
+ QQmlRefPointer<QQmlContextData> effectiveContext;
+ };
+ Contexts getContexts() const;
+
QQmlPlatform *m_platform = nullptr;
QQmlApplication *m_application = nullptr;