How does Qt::connectiontype work?
-
wrote on 21 Apr 2019, 02:07 last edited by
Hello,
I have this:
QObject::connect(m_communicationCenter, &communicationCenter::globalCalRequested, m_motorCenter, &motorCenter::globalCalRequired, static_cast<Qt::ConnectionType>(Qt::UniqueConnection | Qt::DirectConnection));
Yes, it is disgustingly long...
Does this multiple connection type mean that the slot is going to be invoque only once directly on the thread of its QObject?
-
Hello,
I have this:
QObject::connect(m_communicationCenter, &communicationCenter::globalCalRequested, m_motorCenter, &motorCenter::globalCalRequired, static_cast<Qt::ConnectionType>(Qt::UniqueConnection | Qt::DirectConnection));
Yes, it is disgustingly long...
Does this multiple connection type mean that the slot is going to be invoque only once directly on the thread of its QObject?
wrote on 21 Apr 2019, 03:17 last edited by@Factao
From QObject Git File DocumentationBy default, a signal is emitted for every connection you make;
two signals are emitted for duplicate connections. You can break
all of these connections with a single disconnect() call.
If you pass the Qt::UniqueConnection type, the connection will only
be made if it is not a duplicate. If there is already a duplicate
(exact same signal to the exact same slot on the same objects),
the connection will fail and connect will return an invalid QMetaObject::Connection.\note Qt::UniqueConnections do not work for lambdas, non-member functions
and functors; they only apply to connecting to member functions. -
@Factao
From QObject Git File DocumentationBy default, a signal is emitted for every connection you make;
two signals are emitted for duplicate connections. You can break
all of these connections with a single disconnect() call.
If you pass the Qt::UniqueConnection type, the connection will only
be made if it is not a duplicate. If there is already a duplicate
(exact same signal to the exact same slot on the same objects),
the connection will fail and connect will return an invalid QMetaObject::Connection.\note Qt::UniqueConnections do not work for lambdas, non-member functions
and functors; they only apply to connecting to member functions.wrote on 22 Apr 2019, 19:27 last edited byThank you, but I understand the principe of the unique connection. My question was about how passing two connection type like I've done is interpreted. Will it be a direct connection that cannot be duplicated or something else?
-
@Factao said in How does Qt::connectiontype work?:
Qt::UniqueConnection
From the doc:
This is a flag that can be combined with any one of the above connection types, using a bitwise OR. When Qt::UniqueConnection is set, QObject::connect() will fail if the connection already exists (i.e. if the same signal is already connected to the same slot for the same pair of objects). This flag was introduced in Qt 4.6.
So yes, you can combine that flag with one of the others.
-
wrote on 23 Apr 2019, 23:50 last edited by
Thank you!
2/5