From 6314d305ee0d9064ca848980ef2dab1793c191b8 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 25 Mar 2024 14:13:50 +0100 Subject: Generate qmldir files for extra directories with QML files Those qmldir files contain only a prefer directive for the canonical resource location of the module. This way, any time another component from the implicit import is requested, it will not be located in the extra directory (where it probably doesn't exist), but instead in the canonical location. Since people may have manually written qmldir files with different content in those places, or worse, relied on the other components to be inaccessible, we need a new policy to opt into this. Fixes: QTBUG-111763 Change-Id: If236feb7dd7c8d704b813ea56482ff758799d0a7 Reviewed-by: Fabian Kosmale --- tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 29 ++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp') diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index 82cc1fe954..22e04e0df3 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -162,6 +162,8 @@ private slots: void methodOnListLookup(); void methods(); void modulePrefix(); + void multiDirectory_data(); + void multiDirectory(); void multiForeign(); void multiLookup(); void multipleCtors(); @@ -2608,13 +2610,13 @@ void tst_QmlCppCodegen::invisibleSingleton() qmlClearTypeRegistrations(); QQmlEngine engine; - const QUrl copy(u"qrc:/qt/qml/TestTypes/hidden/Main.qml"_s); + const QUrl copy(u"qrc:/qt/qml/HiddenTestTypes/hidden/Main.qml"_s); QQmlComponent c(&engine, copy); QVERIFY2(c.isReady(), qPrintable(c.errorString())); QTest::ignoreMessage( QtWarningMsg, - "qrc:/qt/qml/TestTypes/hidden/Main.qml:4:5: " + "qrc:/qt/qml/HiddenTestTypes/hidden/Main.qml:4:5: " "Unable to assign [undefined] to QColor"); QScopedPointer o(c.create()); QVERIFY(!o.isNull()); @@ -3293,6 +3295,29 @@ void tst_QmlCppCodegen::modulePrefix() QCOMPARE(rootObject->property("baz").toString(), QStringLiteral("ItIsTheSingleton")); } +void tst_QmlCppCodegen::multiDirectory_data() +{ + QTest::addColumn("url"); + QTest::addRow("from qt_add_qml_module") + << QUrl(u"qrc:/qt/qml/TestTypes/extra/extra.qml"_s); +#ifndef VERY_OLD_CMAKE + QTest::addRow("from qt_target_qml_sources") + << QUrl(u"qrc:/qt/qml/TestTypes/extra2/extra.qml"_s); +#endif +} + +void tst_QmlCppCodegen::multiDirectory() +{ + QFETCH(QUrl, url); + QQmlEngine engine; + QQmlComponent component(&engine, url); + QVERIFY2(component.isReady(), qPrintable(component.errorString())); + QScopedPointer rootObject(component.create()); + QVERIFY(rootObject); + + QCOMPARE(rootObject->property("r").value(), QRectF(4, 6, 8, 10)); +} + void tst_QmlCppCodegen::multiForeign() { QQmlEngine engine; -- cgit v1.2.3