diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-10-04 10:22:20 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-10-07 07:51:44 +0200 |
commit | 67fc5b677a05f88f043ea825810b7b244a516b42 (patch) | |
tree | 87cf7254e5006e96061164dfc6b33fa197e2e0f1 /tests/auto/qml | |
parent | a3ccbde329ade1d0102caee1fc84d81a81a55440 (diff) |
tst_qqmlqt.cpp: avoid setContextProperty
Change-Id: Ic8e7c1c4c954fcdd8cf5c1a530652fd4f6ebf119
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/qml')
-rw-r--r-- | tests/auto/qml/qqmlqt/data/formatting.qml | 5 | ||||
-rw-r--r-- | tests/auto/qml/qqmlqt/data/timeRoundtrip.qml | 2 | ||||
-rw-r--r-- | tests/auto/qml/qqmlqt/tst_qqmlqt.cpp | 19 |
3 files changed, 17 insertions, 9 deletions
diff --git a/tests/auto/qml/qqmlqt/data/formatting.qml b/tests/auto/qml/qqmlqt/data/formatting.qml index 7a462c8eeb..f2d1e1b5c8 100644 --- a/tests/auto/qml/qqmlqt/data/formatting.qml +++ b/tests/auto/qml/qqmlqt/data/formatting.qml @@ -41,4 +41,9 @@ QtObject { property string err_dateTime1: Qt.formatDateTime() property string err_dateTime2: Qt.formatDateTime(new Date, new Object) + + property var qdate + property var qtime + property var qdatetime + property var qvariant } diff --git a/tests/auto/qml/qqmlqt/data/timeRoundtrip.qml b/tests/auto/qml/qqmlqt/data/timeRoundtrip.qml index 9d73640c87..65732442af 100644 --- a/tests/auto/qml/qqmlqt/data/timeRoundtrip.qml +++ b/tests/auto/qml/qqmlqt/data/timeRoundtrip.qml @@ -1,6 +1,8 @@ import QtQuick 2.0 +import Test 1.0 QtObject { + required property TimeProvider tp Component.onCompleted: { var t = tp.time; tp.time = t; diff --git a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp index 2d8115e867..15ef31464b 100644 --- a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp +++ b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp @@ -777,10 +777,6 @@ void tst_qqmlqt::dateTimeFormatting() QQmlEngine eng; - eng.rootContext()->setContextProperty("qdate", date); - eng.rootContext()->setContextProperty("qtime", time); - eng.rootContext()->setContextProperty("qdatetime", dateTime); - QQmlComponent component(&eng, testFileUrl("formatting.qml")); QStringList warnings; @@ -794,7 +790,11 @@ void tst_qqmlqt::dateTimeFormatting() foreach (const QString &warning, warnings) QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); - QObject *object = component.create(); + QObject *object = component.createWithInitialProperties({ + {"qdate", date}, + {"qtime", time}, + {"qdatetime", dateTime} + }); QVERIFY2(component.errorString().isEmpty(), qPrintable(component.errorString())); QVERIFY(object != nullptr); @@ -853,7 +853,6 @@ void tst_qqmlqt::dateTimeFormattingVariants() QFETCH(QStringList, expectedResults); QQmlEngine eng; - eng.rootContext()->setContextProperty("qvariant", variant); QQmlComponent component(&eng, testFileUrl("formatting.qml")); QStringList warnings; @@ -867,7 +866,7 @@ void tst_qqmlqt::dateTimeFormattingVariants() foreach (const QString &warning, warnings) QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); - QObject *object = component.create(); + QObject *object = component.createWithInitialProperties({{"qvariant", variant}}); QVERIFY2(component.errorString().isEmpty(), qPrintable(component.errorString())); QVERIFY(object != nullptr); @@ -1174,6 +1173,7 @@ void tst_qqmlqt::qtObjectContents() class TimeProvider: public QObject { Q_OBJECT + QML_NAMED_ELEMENT(TimeProvider) Q_PROPERTY(QTime time READ time WRITE setTime NOTIFY timeChanged) public: @@ -1254,13 +1254,14 @@ void tst_qqmlqt::timeRoundtrip() TimeZoneSwitch tzs(QTest::currentDataTag()); QFETCH(QTime, time); + qmlRegisterTypesAndRevisions<TimeProvider>("Test", 1); TimeProvider tp(time); QQmlEngine eng; - eng.rootContext()->setContextProperty(QLatin1String("tp"), &tp); + //qmlRegisterSingletonInstance("Test", 1, 0, "TimeProvider", &tp); QQmlComponent component(&eng, testFileUrl("timeRoundtrip.qml")); - QObject *obj = component.create(); + QObject *obj = component.createWithInitialProperties({{"tp", QVariant::fromValue(&tp)}}); QVERIFY(obj != nullptr); // QML reads m_getTime and saves the result as m_putTime; this should come out the same, without |