diff options
author | Tor Arne Vestbø <[email protected]> | 2025-04-08 21:48:55 +0200 |
---|---|---|
committer | Tor Arne Vestbø <[email protected]> | 2025-05-24 05:35:22 +0200 |
commit | b6ffbebbbe75c53f8dd9a7afd97032f7f4fd8f5c (patch) | |
tree | b0d54be5e09413c59fbfe1d251d82ba84f22b9a1 /src | |
parent | 1c98b3fe403aaa7b57813070f3bd690af7bd4e43 (diff) |
Use QObjCWeakPointer to track QMacKeyValueObserver observed object
Otherwise we might run the risk that the observed object dies before
we try to do removeObserver.
Pick-to: 6.9
Change-Id: I2b54ff32728fc40fd47be2d14070fc43640f81bf
Reviewed-by: Volker Hilsheimer <[email protected]>
Reviewed-by: Thiago Macieira <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/kernel/qcore_mac_p.h | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/src/corelib/kernel/qcore_mac_p.h b/src/corelib/kernel/qcore_mac_p.h index dc3f172937f..be839debd57 100644 --- a/src/corelib/kernel/qcore_mac_p.h +++ b/src/corelib/kernel/qcore_mac_p.h @@ -407,7 +407,6 @@ public: QMacKeyValueObserver() = default; #if defined( __OBJC__) - // Note: QMacKeyValueObserver must not outlive the object observed! QMacKeyValueObserver(NSObject *object, NSString *keyPath, Callback callback, NSKeyValueObservingOptions options = NSKeyValueObservingOptionNew) : object(object), keyPath(keyPath), callback(new Callback(callback)) @@ -435,7 +434,7 @@ public: void swap(QMacKeyValueObserver &other) noexcept { - qt_ptr_swap(object, other.object); + std::swap(object, other.object); qt_ptr_swap(keyPath, other.keyPath); callback.swap(other.callback); } @@ -445,7 +444,7 @@ private: void addObserver(NSKeyValueObservingOptions options); #endif - NSObject *object = nullptr; + QObjCWeakPointer<NSObject> object; NSString *keyPath = nullptr; std::unique_ptr<Callback> callback; |