aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2023-05-02 17:09:30 +0200
committerUlf Hermann <ulf.hermann@qt.io>2023-05-03 14:38:52 +0200
commit1abfb04fae4a347ea8a96364f682968a956779fb (patch)
tree0a080c065c4cee7d78677e73bae036e23b524b8d /tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp
parentc17226bf98cd0d7cdcf194a23ce6e8d20ca9a770 (diff)
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 <sami.shalayel@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp')
-rw-r--r--tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp26
1 files changed, 26 insertions, 0 deletions
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<QObject> o(c.create());
+ QVERIFY(!o.isNull());
+
+ QQmlComponent *inner = qobject_cast<QQmlComponent *>(o.data());
+ QVERIFY(inner);
+
+ QScopedPointer<QObject> o2(inner->create());
+ QCOMPARE(o2->objectName(), u"foo"_s);
+}
+
QTEST_MAIN(tst_QmlCppCodegen)
#include "tst_qmlcppcodegen.moc"