aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2019-10-22 11:22:11 +0200
committerUlf Hermann <ulf.hermann@qt.io>2019-11-07 16:10:50 +0100
commitce40ac9ed7255c36acdee69b06a7832e492c3fc8 (patch)
treedbe398ae0afecc181d9ab7cdabfe1f4d3fd799ef
parent50bce248ab6ec4d1e39b85029297dc5d5d80f195 (diff)
Register compiled-in QML types
If we compile the QML types into the main application we cannot depend on plugin loading for triggering the registration. Rather, we need to register them immediately. Change-Id: I910fb13359f8b7524eafd7693c85205cb4ed4cd8 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--src/qml/qml/qqmlmetatype.cpp4
-rw-r--r--src/qml/qml/qqmlmetatype_p.h2
-rw-r--r--src/qml/qml/qqmlmetatypedata.cpp7
-rw-r--r--src/qml/qml/qqmlmetatypedata_p.h2
-rw-r--r--src/qml/qml/qqmltypeloader.cpp3
-rw-r--r--tests/auto/qml/qqmltypeloader/data/declarativeCppType.qml6
-rw-r--r--tests/auto/qml/qqmltypeloader/declarativetesttype.h44
-rw-r--r--tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp10
-rw-r--r--tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.pro8
9 files changed, 77 insertions, 9 deletions
diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp
index af43bfc921..b8c17c9374 100644
--- a/src/qml/qml/qqmlmetatype.cpp
+++ b/src/qml/qml/qqmlmetatype.cpp
@@ -278,10 +278,10 @@ void QQmlMetaType::qmlInsertModuleRegistration(const QString &uri, int majorVers
data->moduleTypeRegistrationFunctions.insert(versionedUri, registerFunction);
}
-void QQmlMetaType::qmlRegisterModuleTypes(const QString &uri, int majorVersion)
+bool QQmlMetaType::qmlRegisterModuleTypes(const QString &uri, int majorVersion)
{
QQmlMetaTypeDataPtr data;
- data->registerModuleTypes(QQmlMetaTypeData::VersionedUri(uri, majorVersion));
+ return data->registerModuleTypes(QQmlMetaTypeData::VersionedUri(uri, majorVersion));
}
void QQmlMetaType::clearTypeRegistrations()
diff --git a/src/qml/qml/qqmlmetatype_p.h b/src/qml/qml/qqmlmetatype_p.h
index 146a5ab136..ed4675046d 100644
--- a/src/qml/qml/qqmlmetatype_p.h
+++ b/src/qml/qml/qqmlmetatype_p.h
@@ -200,7 +200,7 @@ public:
static void qmlInsertModuleRegistration(const QString &uri, int majorVersion,
void (*registerFunction)());
- static void qmlRegisterModuleTypes(const QString &uri, int majorVersion);
+ static bool qmlRegisterModuleTypes(const QString &uri, int majorVersion);
};
Q_DECLARE_TYPEINFO(QQmlMetaType, Q_MOVABLE_TYPE);
diff --git a/src/qml/qml/qqmlmetatypedata.cpp b/src/qml/qml/qqmlmetatypedata.cpp
index c2150225c3..ed885eaa97 100644
--- a/src/qml/qml/qqmlmetatypedata.cpp
+++ b/src/qml/qml/qqmlmetatypedata.cpp
@@ -78,11 +78,14 @@ void QQmlMetaTypeData::registerType(QQmlTypePrivate *priv)
priv->release();
}
-void QQmlMetaTypeData::registerModuleTypes(const QQmlMetaTypeData::VersionedUri &versionedUri)
+bool QQmlMetaTypeData::registerModuleTypes(const QQmlMetaTypeData::VersionedUri &versionedUri)
{
auto function = moduleTypeRegistrationFunctions.constFind(versionedUri);
- if (function != moduleTypeRegistrationFunctions.constEnd())
+ if (function != moduleTypeRegistrationFunctions.constEnd()) {
(*function)();
+ return true;
+ }
+ return false;
}
QQmlPropertyCache *QQmlMetaTypeData::propertyCacheForMinorVersion(int index, int minorVersion) const
diff --git a/src/qml/qml/qqmlmetatypedata_p.h b/src/qml/qml/qqmlmetatypedata_p.h
index 755a51a16e..f193e51f5a 100644
--- a/src/qml/qml/qqmlmetatypedata_p.h
+++ b/src/qml/qml/qqmlmetatypedata_p.h
@@ -101,7 +101,7 @@ struct QQmlMetaTypeData
TypeModules uriToModule;
QHash<VersionedUri, void (*)()> moduleTypeRegistrationFunctions;
- void registerModuleTypes(const VersionedUri &versionedUri);
+ bool registerModuleTypes(const VersionedUri &versionedUri);
QBitArray objects;
QBitArray interfaces;
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp
index c2870396b0..b164f5873c 100644
--- a/src/qml/qml/qqmltypeloader.cpp
+++ b/src/qml/qml/qqmltypeloader.cpp
@@ -598,7 +598,8 @@ bool QQmlTypeLoader::Blob::addImport(QQmlTypeLoader::Blob::PendingImportPtr impo
}
} else {
// Is this a module?
- if (QQmlMetaType::isAnyModule(import->uri)) {
+ if (QQmlMetaType::isAnyModule(import->uri)
+ || QQmlMetaType::qmlRegisterModuleTypes(import->uri, import->majorVersion)) {
if (!m_importCache.addLibraryImport(importDatabase, import->uri, import->qualifier, import->majorVersion,
import->minorVersion, QString(), QString(), false, errors))
return false;
diff --git a/tests/auto/qml/qqmltypeloader/data/declarativeCppType.qml b/tests/auto/qml/qqmltypeloader/data/declarativeCppType.qml
new file mode 100644
index 0000000000..9061f3beb5
--- /dev/null
+++ b/tests/auto/qml/qqmltypeloader/data/declarativeCppType.qml
@@ -0,0 +1,6 @@
+import QtQml 2.0
+import declarative.import.for.typeloader.test 3.2
+
+DeclarativeTestType {
+ objectName: "ddddd"
+}
diff --git a/tests/auto/qml/qqmltypeloader/declarativetesttype.h b/tests/auto/qml/qqmltypeloader/declarativetesttype.h
new file mode 100644
index 0000000000..a21cdcfd1d
--- /dev/null
+++ b/tests/auto/qml/qqmltypeloader/declarativetesttype.h
@@ -0,0 +1,44 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef DECLARATIVETESTTYPE_H
+#define DECLARATIVETESTTYPE_H
+
+#include <QObject>
+#include <qqml.h>
+
+class DeclarativeTestType : public QObject
+{
+ Q_OBJECT
+ QML_ELEMENT
+
+public:
+ explicit DeclarativeTestType(QObject *parent = nullptr) : QObject(parent) {}
+};
+
+#endif // DECLARATIVETESTTYPE_H
diff --git a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp
index 9ad53aaa8b..e90f53d389 100644
--- a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp
+++ b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp
@@ -61,6 +61,7 @@ private slots:
void qrcRootPathUrl();
void implicitImport();
void compositeSingletonCycle();
+ void declarativeCppType();
};
void tst_QQMLTypeLoader::testLoadComplete()
@@ -542,6 +543,15 @@ void tst_QQMLTypeLoader::compositeSingletonCycle()
QCOMPARE(qvariant_cast<QColor>(object->property("color")), QColorConstants::Black);
}
+void tst_QQMLTypeLoader::declarativeCppType()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("declarativeCppType.qml"));
+ QCOMPARE(component.status(), QQmlComponent::Ready);
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY(!obj.isNull());
+}
+
QTEST_MAIN(tst_QQMLTypeLoader)
#include "tst_qqmltypeloader.moc"
diff --git a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.pro b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.pro
index 0352561e03..50f94405f4 100644
--- a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.pro
+++ b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.pro
@@ -1,4 +1,4 @@
-CONFIG += testcase
+CONFIG += testcase qmltypes
TARGET = tst_qqmltypeloader
QT += qml testlib qml-private quick
macx:CONFIG -= app_bundle
@@ -8,7 +8,11 @@ SOURCES += \
../../shared/testhttpserver.cpp
HEADERS += \
- ../../shared/testhttpserver.h
+ ../../shared/testhttpserver.h \
+ declarativetesttype.h
+
+IMPORT_VERSION = 3.2
+QML_IMPORT_NAME = "declarative.import.for.typeloader.test"
include (../../shared/util.pri)