QObject::connect: Cannot queue arguments of type 'QTextCursor'
-
@hskoglund said in QObject::connect: Cannot queue arguments of type 'QTextCursor':
googled a bit about connect() to lambdas across threads and it looks that when the signal is emitted to a lambda the detection if it's across threads or not indeed is shaky.
This makes no sense Henry, a lambda is at best just a regular object it has no notion of threads to begin with. That's why you can specify context
QObject
(and you should) when connecting signals to lambdas. -
@kshegunov Thanks for the clarification, it makes sense., i.e. the detection is not "shaky" it's impossible to do!
I should have a coffee and study the source code for how that detection is done when signals are emitted across threads.
And, this "problem" with connecting to lambdas across threads should be documented better I think.
-
@hskoglund said in QObject::connect: Cannot queue arguments of type 'QTextCursor':
Thanks for the clarification, it makes sense., i.e. the detection is not "shaky" it's impossible to do!
Exactly!
I should have a coffee and study the source code for how that detection is done when signals are emitted across threads.
Coffee sounds nice, I'm now envious ... ;)
You can look here about the second part:
https://code.woboq.org/qt5/qtbase/src/corelib/kernel/qobject.cpp.html#_ZN11QMetaObject8activateEP7QObjectiiPPvAnd, this "problem" with connecting to lambdas across threads should be documented better I think.
Perhaps you're right, but I'm too lazy to check what it really says in the docs ... :p
However I think it's documented, probably more emphasis can be put though. -
@bachir Hi there,
sorry for digging this up. How did you get to compile this lambda connection with the additional argument? I still cannot do that.This works:
connect(uap, &CUaProxy::uaItemChanged, [this, i]( const CUaProxy::MsgType msgt, const int riskIndex, const QVariant& value) { this->onUaMsgReceived(msgt, i, riskIndex, value); });
This doesnt compile:
connect(uap, &CUaProxy::uaItemChanged, [this, i]( const CUaProxy::MsgType msgt, const int riskIndex, const QVariant& value) { this->onUaMsgReceived(msgt, i, riskIndex, value); }, Qt::BlockingQueuedConnection);
Would appreciate your feedback.
-
@Bremenpl said in QObject::connect: Cannot queue arguments of type 'QTextCursor':
This doesnt compile:
And what compiler error do you get?
-
@Christian-Ehrlicher Sorry I didnt add it, here it is:
cintegrator.cpp:63: error: no matching member function for call to 'connect' cintegrator.cpp:70: error: no matching function for call to 'CIntegrator::connect(CUaProxy*&, void (CUaProxy::*)(CUaProxy::MsgType, int, const QVariant&), CIntegrator::uaInit()::<lambda(CUaProxy::MsgType, int, const QVariant&)>, Qt::ConnectionType)' }, Qt::DirectConnection); ^ qobject.h:228: error: no type named 'Object' in 'struct QtPrivate::FunctionPointer<Qt::ConnectionType>'
-
@Bremenpl said in QObject::connect: Cannot queue arguments of type 'QTextCursor':
Sorry I didnt add it, here it is
You can't have blocking queued connection (or explicitly specify the connection type for that matter) without specifying a context object. Qt can't know what's the receiving thread this is supposed to block.
-
@Bremenpl said in QObject::connect: Cannot queue arguments of type 'QTextCursor':
To be honest this was just an example. Originally I was aiming for Qt::DirectConnection which doesnt compile as well (same errors).
Give context object. Otherwise specifying a connection type makes no sense whatsoever. If the slot's to be called in the emitting thread then you can omit the connection type, and then it implies "direct". In all other cases you must know what's the receiving thread, which you can specify only through a
QObject
you pass as context.How to point the context object?
-
@kshegunov Right... Thanks, something didnt trigger in the brain. Now its fine:
connect(uap, &CUaProxy::uaItemChanged, this, [this, i]( const CUaProxy::MsgType msgt, const int riskIndex, const QVariant& value) { this->onUaMsgReceived(msgt, i, riskIndex, value); }, Qt::QueuedConnection);
Also needed
Qt::QueuedConnection
eventually.