diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2024-03-01 14:22:47 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2024-03-19 11:51:00 +0100 |
commit | 476e503cfbc42b8ea9e94a1f536d443fc8ce69c0 (patch) | |
tree | 8b72ad36449f100255a2293ca6c1f577ddadef54 /src/corelib/kernel/qpropertyprivate.h | |
parent | 7071010880191e07fbcfd8aac876e396b462f956 (diff) |
QProperty: Use RefCounted as intended
You're not supposed to mess with the refcount directly. That's what the
addRef() and deref() methods are for.
Change-Id: I5cae946cef7ac72dd99b247ade95590d142c269e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/kernel/qpropertyprivate.h')
-rw-r--r-- | src/corelib/kernel/qpropertyprivate.h | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/corelib/kernel/qpropertyprivate.h b/src/corelib/kernel/qpropertyprivate.h index 28cc04ff9d..86dc08a6bc 100644 --- a/src/corelib/kernel/qpropertyprivate.h +++ b/src/corelib/kernel/qpropertyprivate.h @@ -36,9 +36,13 @@ namespace QtPrivate { // QPropertyBindingPrivatePtr operates on a RefCountingMixin solely so that we can inline // the constructor and copy constructor struct RefCounted { + + int refCount() const { return ref; } + void addRef() { ++ref; } + bool deref() { return --ref != 0; } + +private: int ref = 0; - void addRef() {++ref;} - bool deref() {--ref; return ref;} }; } @@ -61,7 +65,7 @@ public: QPropertyBindingPrivatePtr() noexcept : d(nullptr) { } ~QPropertyBindingPrivatePtr() { - if (d && (--d->ref == 0)) + if (d && !d->deref()) destroyAndFreeMemory(); } Q_CORE_EXPORT void destroyAndFreeMemory(); |