diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2022-09-15 09:36:13 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2022-09-16 01:07:33 +0200 |
commit | f09f5ccd9b769252b08e62a538adaa31edf6b9b4 (patch) | |
tree | 9439701fae825e34f065fb281592e759cfc57b6f /src/qml/qml/qqmldatablob_p.h | |
parent | f1f43ec31ba4e5f20c3bec24f5d4a5756d16cc66 (diff) |
QQmlDataBlob: Use RefPointer when interacting with QQmlTypeLoader
QQmlTypeloader and QQmlTypeLoaderThread so far used to manually call ref
and deref on QQmlDataBlob pointers. Changing the refcount was necessary,
as the blobs were stored in various data structures which should keep
the blobs alive; namely the Message struct subclasses use in QQmlThread
and the NetworkReplies hash-map.
However, the whole setup was rather brittle; especially when it comes to
QQmlThread, where methods adding Message structs would increment the
refcount, and the actual callback stored in the Message would decrement
it. This would obviously cause leaks if the Message::call would not be
invoked (e.g. due to the QQmlThread shutting down).
By replacing the raw pointers with QQmlDataBlob::Ptr (which is a new
typedef for QQmlRefPointer<QQmlDataBlob>), we can avoid the whole
issue[1], and also simplify the code. Note that Message stores a
QQmlDataBlob::Ptr by virtue of inferring the type from its stored
method.
[1]: At least in theory; QQmlThread does not clean up its message list
on shut-down so far.
Change-Id: I6aaf5a9dcddfd38795059518ca2d3650072bcda3
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/qml/qml/qqmldatablob_p.h')
-rw-r--r-- | src/qml/qml/qqmldatablob_p.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/qml/qml/qqmldatablob_p.h b/src/qml/qml/qqmldatablob_p.h index e975043871..522d02e97a 100644 --- a/src/qml/qml/qqmldatablob_p.h +++ b/src/qml/qml/qqmldatablob_p.h @@ -38,6 +38,8 @@ class QQmlTypeLoader; class Q_QML_PRIVATE_EXPORT QQmlDataBlob : public QQmlRefCount { public: + using Ptr = QQmlRefPointer<QQmlDataBlob>; + enum Status { Null, // Prior to QQmlTypeLoader::load() Loading, // Prior to data being received and dataReceived() being called |