aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2020-01-29 13:22:35 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2020-01-29 15:27:15 +0100
commitda9fee11bbf7842d72bbf7c0cd2072b020c71626 (patch)
treeb95ede099d5d2a48a6d8c7eaad14267e6217ef7e /tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
parent4ad7a4d3dabea0c46872be2d6262a9c00e4e5079 (diff)
Required properties: Allow required default properties
This was already possible from C++, this change adds the required changes to the grammar to allow declaring required default properties in QML. Change-Id: I76cb4d70e573bf161676da8295ab257fe95ed4ae Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp')
-rw-r--r--tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
index 2acc62ca28..43cbd93396 100644
--- a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
+++ b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
@@ -671,8 +671,20 @@ void tst_qqmlcomponent::setDataNoEngineNoSegfault()
QVERIFY(!c);
}
+class RequiredDefaultCpp : public QObject
+{
+ Q_OBJECT
+public:
+ Q_PROPERTY(QQuickItem *defaultProperty MEMBER m_defaultProperty NOTIFY defaultPropertyChanged REQUIRED)
+ Q_SIGNAL void defaultPropertyChanged();
+ Q_CLASSINFO("DefaultProperty", "defaultProperty")
+private:
+ QQuickItem *m_defaultProperty = nullptr;
+};
+
void tst_qqmlcomponent::testRequiredProperties_data()
{
+ qmlRegisterType<RequiredDefaultCpp>("qt.test", 1, 0, "RequiredDefaultCpp");
QTest::addColumn<QUrl>("testFile");
QTest::addColumn<bool>("shouldSucceed");
QTest::addColumn<QString>("errorMsg");
@@ -687,6 +699,10 @@ void tst_qqmlcomponent::testRequiredProperties_data()
QTest::addRow("setLater") << testFileUrl("requiredSetLater.qml") << true << "";
QTest::addRow("setViaAliasToSubcomponent") << testFileUrl("setViaAliasToSubcomponent.qml") << true << "";
QTest::addRow("aliasToSubcomponentNotSet") << testFileUrl("aliasToSubcomponentNotSet.qml") << false << "It can be set via the alias property i_alias";
+ QTest::addRow("required default set") << testFileUrl("requiredDefault.1.qml") << true << "";
+ QTest::addRow("required default not set") << testFileUrl("requiredDefault.2.qml") << false << "Required property requiredDefault was not initialized";
+ QTest::addRow("required default set (C++)") << testFileUrl("requiredDefault.3.qml") << true << "";
+ QTest::addRow("required default not set (C++)") << testFileUrl("requiredDefault.4.qml") << false << "Required property defaultProperty was not initialized";
}