diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-07-08 17:34:58 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-07-09 22:34:46 +0200 |
commit | f9e167409486998b76cedd8ce50ca1381bcd6e6a (patch) | |
tree | 0f3d490ac724df79dcf085481838eeee6e67cc97 /tests/auto/tools/moc/tst_moc.cpp | |
parent | 577558daf5a2709722cb7980f194cbbc6a8287a3 (diff) |
moc: For non-STORED QProperties, expect a pointer
This way we can return a nullptr for cases where the class does not want
to provide a property at all. For example outside of bindings when
reading the default value. The moc-generated code can check for such
nullptrs and handle them.
Change-Id: I7ff478cb254012147bb7aed3feb160e3e679cb6d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/tools/moc/tst_moc.cpp')
-rw-r--r-- | tests/auto/tools/moc/tst_moc.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index 14c61d552d..4ea376df68 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -4195,19 +4195,19 @@ public: void onLazyTestPropertyChanged() { q->lazyTestPropertyChanged(); } - QNotifiedProperty<int, &Private::onLazyTestPropertyChanged> &lazyTestProperty() { - if (!lazyTestPropertyStorage) - lazyTestPropertyStorage.reset(new QNotifiedProperty<int, &Private::onLazyTestPropertyChanged>); - return *lazyTestPropertyStorage; + const QNotifiedProperty<int, &Private::onLazyTestPropertyChanged> *lazyTestProperty() const { + // Mind that this prevents the property read from being recorded. + // For real-world use cases some more logic is necessary here. + return lazyTestPropertyStorage.data(); } - const QNotifiedProperty<int, &Private::onLazyTestPropertyChanged> &lazyTestProperty() const { + QNotifiedProperty<int, &Private::onLazyTestPropertyChanged> *lazyTestProperty() { if (!lazyTestPropertyStorage) lazyTestPropertyStorage.reset(new QNotifiedProperty<int, &Private::onLazyTestPropertyChanged>); - return *lazyTestPropertyStorage; + return lazyTestPropertyStorage.data(); } - mutable QScopedPointer<QNotifiedProperty<int, &Private::onLazyTestPropertyChanged>> lazyTestPropertyStorage; + QScopedPointer<QNotifiedProperty<int, &Private::onLazyTestPropertyChanged>> lazyTestPropertyStorage; }; Private priv{this}; @@ -4245,7 +4245,7 @@ void tst_Moc::privateQPropertyShim() QCOMPARE(testObject.lazyTestProperty(), 0); // Explicitly set to something - testObject.priv.lazyTestProperty().setValue(&testObject.priv, 42); + testObject.priv.lazyTestProperty()->setValue(&testObject.priv, 42); QCOMPARE(testObject.property("lazyTestProperty").toInt(), 42); // Behave like a QProperty |