diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-12-07 19:02:39 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-01-25 23:55:27 +0100 |
commit | 71597472ddbe6957f47ae61b72c147846a80f16f (patch) | |
tree | 756ce46b97f0487e86c50736abe0f74dff0dc742 /src/qml/qml/qqmlproperty.cpp | |
parent | d6eaa70859fbec0f02d15bd8e8fd6ddc360ab371 (diff) |
Avoid ping-pong between plain pointers and QQmlRefPointer
We want to deal in QQmlRefPointer as much as possible. In particular,
assigning nullptr to a QQmlRefPointer triggers the creation of an empty
QQmlRefPointer and the assignment of that one. Provide a reset() method
to do this in a cleaner way.
In turn, make QQmlGuardedContextData::reset() private. It's really
dangerous and should not be called from outside. setContextData() is
safer but may do additional work. The only place from where reset() was
previously called in its public capacity is probably dead code, though.
Change-Id: Idb72e255dbfad6e5dd963dc76d719bb9edc10471
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlproperty.cpp')
-rw-r--r-- | src/qml/qml/qqmlproperty.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp index 5753a2cb33..31cc9374b4 100644 --- a/src/qml/qml/qqmlproperty.cpp +++ b/src/qml/qml/qqmlproperty.cpp @@ -152,8 +152,10 @@ QQmlProperty::QQmlProperty(QObject *obj) QQmlProperty::QQmlProperty(QObject *obj, QQmlContext *ctxt) : d(new QQmlPropertyPrivate) { - d->context = ctxt?QQmlContextData::get(ctxt):nullptr; - d->engine = ctxt?ctxt->engine():nullptr; + if (ctxt) { + d->context = QQmlContextData::get(ctxt); + d->engine = ctxt->engine(); + } d->initDefault(obj); } @@ -204,12 +206,15 @@ QQmlProperty::QQmlProperty(QObject *obj, const QString &name) QQmlProperty::QQmlProperty(QObject *obj, const QString &name, QQmlContext *ctxt) : d(new QQmlPropertyPrivate) { - d->context = ctxt?QQmlContextData::get(ctxt):nullptr; - d->engine = ctxt?ctxt->engine():nullptr; + if (ctxt) { + d->context = QQmlContextData::get(ctxt); + d->engine = ctxt->engine(); + } + d->initProperty(obj, name); if (!isValid()) { d->object = nullptr; - d->context = nullptr; + d->context.reset(); d->engine = nullptr; } } @@ -226,7 +231,7 @@ QQmlProperty::QQmlProperty(QObject *obj, const QString &name, QQmlEngine *engine d->initProperty(obj, name); if (!isValid()) { d->object = nullptr; - d->context = nullptr; + d->context.reset(); d->engine = nullptr; } } @@ -243,7 +248,7 @@ QQmlProperty QQmlPropertyPrivate::create(QObject *target, const QString &propert d->initProperty(target, propertyName, flags); if (!result.isValid()) { d->object = nullptr; - d->context = nullptr; + d->context.reset(); d->engine = nullptr; } return result; |