From 1abfb04fae4a347ea8a96364f682968a956779fb Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 2 May 2023 17:09:30 +0200 Subject: QmlCompiler: Do not stop parsing on top-level Component elements This just creates an inconsistent state where some of the document has been parsed and some hasn't. The only thing we actually need is the log message. Also, fix the warning message. Amends commit 169f0f71665a3a5155f8d63a9c11bc2484353561. Pick-to: 6.5 Fixes: QTBUG-112897 Change-Id: Ie8486909f9bea9ee1b87f2857f7b77fb7cc561e8 Reviewed-by: Sami Shalayel --- tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (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 e3292b52f3..0814d92429 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -184,6 +184,7 @@ private slots: void jsArrayMethodsWithParams_data(); void jsArrayMethodsWithParams(); void shadowedMethod(); + void topLevelComponent(); }; void tst_QmlCppCodegen::initTestCase() @@ -3767,6 +3768,31 @@ void tst_QmlCppCodegen::shadowedMethod() QCOMPARE(o->property("cthing"), QVariant::fromValue(u"c"_s)); } +void tst_QmlCppCodegen::topLevelComponent() +{ + // TODO: Once we stop accepting top level Component elements, this test can be removed. + + QQmlEngine e; + + const QUrl url(u"qrc:/qt/qml/TestTypes/topLevelComponent.qml"_s); + QTest::ignoreMessage( + QtWarningMsg, + qPrintable(url.toString() + u":4:1: Using a Component as the root of a QML document " + "is deprecated: types defined in qml documents are " + "automatically wrapped into Components when needed."_s)); + + QQmlComponent c(&e, url); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer o(c.create()); + QVERIFY(!o.isNull()); + + QQmlComponent *inner = qobject_cast(o.data()); + QVERIFY(inner); + + QScopedPointer o2(inner->create()); + QCOMPARE(o2->objectName(), u"foo"_s); +} + QTEST_MAIN(tst_QmlCppCodegen) #include "tst_qmlcppcodegen.moc" -- cgit v1.2.3