diff options
author | Dario Freddi <dario.freddi@ispirata.com> | 2013-07-17 00:39:23 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-16 23:46:30 +0200 |
commit | 76b06f993e534e02e35830ac0d8f41e546463945 (patch) | |
tree | 08a76949780dc0e74214c3052efbedaa741fc4fb /src/corelib/doc/snippets/code | |
parent | ae577e6b8f8b966cf87293b12803bcc813019a2e (diff) |
QObject: allow connecting to functors with a receiver object
Up to now, it was only possible to connect to functors in a direct
way, without being capable of using Qt::ConnectionType. This patch
allows for specifying a receiver for Functors and function
pointers, hence making it possible to specify effectively the
connection type.
To do this properly, it was needed to add an enum in FunctionPointer
representing whether the considered function is a member function
or not, to reduce ambiguity upon overloaded calls.
Moreover, now senders are checked for the existence of a slot obj
as well. This way, should the context be freed, the slot obj and
the functor contained in it will be freed as well.
On a side note, connecting to a static slot
(like QCoreApplication::quit) specifying the receiver object is
now compiling.
Change-Id: I46474099413b1dc6ca4db9934191d469baeef070
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/doc/snippets/code')
-rw-r--r-- | src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp index 6a2305cc85..4ecc1758ae 100644 --- a/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp @@ -472,6 +472,21 @@ if (isSignalConnected(valueChangedSignal)) { } //! [49] +//! [50] +void someFunction(); +QPushButton *button = new QPushButton; +QObject::connect(button, &QPushButton::clicked, this, someFunction, Qt::QueuedConnection); +//! [50] + +//! [51] +QByteArray page = ...; +QTcpSocket *socket = new QTcpSocket; +socket->connectToHost("qt-project.org", 80); +QObject::connect(socket, &QTcpSocket::connected, this, [=] () { + socket->write("GET " + page + "\r\n"); + }, Qt::AutoConnection); +//! [51] + //! [meta data] //: This is a comment for the translator. //= qtn_foo_bar |