summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qobject_p.h
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2011-11-11 17:01:06 +0100
committerQt by Nokia <qt-info@nokia.com>2011-11-25 01:12:14 +0100
commit79f675a1e0f628bbc25345ebc1eb1f5809166c6b (patch)
tree998a846e047fcadb588d9922f6aa8aaa6bd562e0 /src/corelib/kernel/qobject_p.h
parente759f9580ef0a76131c7540015a87968742fce9f (diff)
Change the return value of QObject::connect
From a bool to a handle to to connection. Also added a new overload of disconnect that disconnect a handle This is required because with the new syntax taking lambda or functors, it is the only way to disconnect a connection (as it is impossible to compare functors) The new return value is QMetaObject::Connection, it is a wrapper around the internal QObjectPrivate::Connection. QObjectPrivate::Connection is now reference counted. tst_qglobal.cpp: This test set up an internal callback, and the callback do not set any proper connection handle (and tbh, it would be hard for it to do so). So the returned QMetaObject::Connection is invalid, and ok is false (Internal callbacks are only used for jambi and should probably be removed) Change-Id: I111626fb4f47efc4db5e2ea5bff9da15f08fea7b Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qobject_p.h')
-rw-r--r--src/corelib/kernel/qobject_p.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h
index b4c30bd149..2a9334ae8f 100644
--- a/src/corelib/kernel/qobject_p.h
+++ b/src/corelib/kernel/qobject_p.h
@@ -121,11 +121,22 @@ public:
Connection *next;
Connection **prev;
QAtomicPointer<int> argumentTypes;
+ QAtomicInt ref_;
ushort method_offset;
ushort method_relative;
ushort connectionType : 3; // 0 == auto, 1 == direct, 2 == queued, 4 == blocking
+ Connection() : nextConnectionList(0), ref_(2) {
+ //ref_ is 2 for the use in the internal lists, and for the use in QMetaObject::Connection
+ }
~Connection();
int method() const { return method_offset + method_relative; }
+ void ref() { ref_.ref(); }
+ void deref() {
+ if (!ref_.deref()) {
+ Q_ASSERT(!receiver);
+ delete this;
+ }
+ }
};
// ConnectionList is a singly-linked list
struct ConnectionList {