aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlcomponent.h
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2022-03-31 16:28:24 +0200
committerUlf Hermann <ulf.hermann@qt.io>2022-11-10 14:00:11 +0000
commitfa0be265e4c6a8528778a41fdd376b26cb70db74 (patch)
treeaaddda46b53b4f5a5bea75ba523302dcf8bcfea3 /src/qml/qml/qqmlcomponent.h
parenta1cd5b446f5dd61f0792e5a394f45c8d28455793 (diff)
Long live QQmlComponent::loadFromModule!
loadFromModule is conceptually similar to loadUrl, except that it does load the Component from a QML module URI and a typename instead of an URL. One big difference is that it allows loading types registered in C++, which is not possible via URLs, as those types do not have any. The implementation piggy-backs on the existing functionality of the QQmlTypeLoader: We first add the URI as an import. Then we resolve the QQmlTypeModule matching the URI. For a C++ registered type, we can already find the existing QQmlType there. As we don't store the QQmlTypes for composite types theree, we might however not find the type, even if it exists. To handle that case, we then use QQmlImports::resolveType. This is not too costly, as import and module resolution get cached. For composite types, we then retrieve their URL, and simply fall back to loadUrl. This could be optimized, but is done in the simplest way for now. For C++ registered types, we store the QQmlType in the component instead. Doing that allows us to use QQmlType::createWithQQmlData in QQmlComponent::beginCreate. Compared to loadFromUrl there are a few additional failure modes: attempting to load singletons, querying non-existing modules, or asking for non-existing types in a module. Those all result in component entering an error state. The API ignores revisioning – it is questionable whether we want to support it, or if we can live with only resolving to the latest version. Adding support for it at a later point would be easy; one would simply need to pass a QTypeRevision through the various APIs. There are two remaining tasks after this patch: We do not validate required properties for C++ types with this approach, and we cannot load inline components. Both will ba addressed in follow up patches. Task-number: QTBUG-97156 Change-Id: If3ed74a499f49c668524d917089a0c237c4ddaf8 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlcomponent.h')
-rw-r--r--src/qml/qml/qqmlcomponent.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlcomponent.h b/src/qml/qml/qqmlcomponent.h
index ca95d756a5..daa95df135 100644
--- a/src/qml/qml/qqmlcomponent.h
+++ b/src/qml/qml/qqmlcomponent.h
@@ -52,6 +52,10 @@ public:
QQmlComponent(QQmlEngine *, const QString &fileName, CompilationMode mode, QObject *parent = nullptr);
QQmlComponent(QQmlEngine *, const QUrl &url, QObject *parent = nullptr);
QQmlComponent(QQmlEngine *, const QUrl &url, CompilationMode mode, QObject *parent = nullptr);
+
+ QQmlComponent(QQmlEngine *engine, QAnyStringView uri, QAnyStringView typeName, QObject *parent = nullptr);
+ QQmlComponent(QQmlEngine *engine, QAnyStringView uri, QAnyStringView typeName, CompilationMode mode, QObject *parent = nullptr);
+
~QQmlComponent() override;
enum Status { Null, Ready, Loading, Error };
@@ -89,6 +93,8 @@ public:
public Q_SLOTS:
void loadUrl(const QUrl &url);
void loadUrl(const QUrl &url, CompilationMode mode);
+ void loadFromModule(QAnyStringView uri, QAnyStringView typeName,
+ QQmlComponent::CompilationMode mode = PreferSynchronous);
void setData(const QByteArray &, const QUrl &baseUrl);
Q_SIGNALS: