aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2024-02-21 15:01:17 +0100
committerUlf Hermann <ulf.hermann@qt.io>2024-02-22 22:45:13 +0100
commit05a9fa44378a96838d56b37eaa59223919d5a721 (patch)
treef968dfa069010597e5aaab692132c1561b3ecc2b /tests/auto/qml/qqmlimport/tst_qqmlimport.cpp
parent406e6054184f87edfbca06cd9ce2a6a7daed9aca (diff)
QtQml: Load C++-defined types also for the implicit import
If the implicit import does not declare a plugin, that doesn't mean we don't want to load its C++-defined types. Pick-to: 6.7 Change-Id: I23427a91f7801cab3a18a5b01c45c520fae7e271 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests/auto/qml/qqmlimport/tst_qqmlimport.cpp')
-rw-r--r--tests/auto/qml/qqmlimport/tst_qqmlimport.cpp65
1 files changed, 51 insertions, 14 deletions
diff --git a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp
index f08a8d423a..37a90a74b4 100644
--- a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp
+++ b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp
@@ -1,23 +1,49 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-#include <QtCore/qscopeguard.h>
-#include <QtTest/QtTest>
-#include <QQmlApplicationEngine>
-#include <QQmlAbstractUrlInterceptor>
+#include <private/qmlutils_p.h>
+#include <private/qqmlengine_p.h>
+#include <private/qqmlimport_p.h>
+
#include <QtQuick/qquickview.h>
#include <QtQuick/qquickitem.h>
-#include <private/qqmlimport_p.h>
-#include <private/qqmlengine_p.h>
-#include <QtQuickTestUtils/private/qmlutils_p.h>
-#include <QQmlComponent>
+
+#include <QtTest/qsignalspy.h>
+
+#include <QtQml/qqmlabstracturlinterceptor.h>
+#include <QtQml/qqmlapplicationengine.h>
+#include <QtQml/qqmlcomponent.h>
+#include <QtQml/qqmlmoduleregistration.h>
+
+#include <QtCore/qscopeguard.h>
+#include <QtCore/qlibraryinfo.h>
+
+class TheThing : public QObject
+{
+ Q_OBJECT
+ QML_ELEMENT
+ Q_PROPERTY(int width MEMBER m_width FINAL)
+
+public:
+ int m_width = 12;
+};
+
+void qml_register_types_noimport()
+{
+ qmlRegisterTypesAndRevisions<TheThing>("noimport", 1);
+ qmlRegisterModule("noimport", 1, 0);
+}
class tst_QQmlImport : public QQmlDataTest
{
Q_OBJECT
public:
- tst_QQmlImport();
+ tst_QQmlImport()
+ : QQmlDataTest(QT_QMLTEST_DATADIR)
+ , noimportRegistration("noimport", qml_register_types_noimport)
+ {
+ }
private slots:
void importPathOrder();
@@ -40,6 +66,10 @@ private slots:
void implicitWithDependencies();
void qualifiedScriptImport();
void invalidImportUrl();
+ void registerTypesFromImplicitImport();
+
+private:
+ QQmlModuleRegistration noimportRegistration;
};
void tst_QQmlImport::cleanup()
@@ -150,6 +180,18 @@ void tst_QQmlImport::invalidImportUrl()
":2 Cannot resolve URL for import \"file://./MyModuleName\"\n"));
}
+void tst_QQmlImport::registerTypesFromImplicitImport()
+{
+ QQmlEngine engine;
+ QQmlComponent c(&engine, testFileUrl("noimport/Main.qml"));
+ QVERIFY2(c.isReady(), qPrintable(c.errorString()));
+ QScopedPointer<QObject> o(c.create());
+ QVERIFY(!o.isNull());
+ TheThing *t = qobject_cast<TheThing *>(o.data());
+ QVERIFY(t);
+ QCOMPARE(t->m_width, 640);
+}
+
void tst_QQmlImport::testDesignerSupported()
{
std::unique_ptr<QQuickView> window = std::make_unique<QQuickView>();
@@ -219,11 +261,6 @@ void tst_QQmlImport::uiFormatLoading()
QVERIFY(test->rootObjects()[size -1]->property("success").toBool());
}
-tst_QQmlImport::tst_QQmlImport()
- : QQmlDataTest(QT_QMLTEST_DATADIR)
-{
-}
-
void tst_QQmlImport::importPathOrder()
{
#ifdef Q_OS_ANDROID