Solved Passing QFlags between threads
-
Dear all,
using Qt4.8.7, I'm in trouble trying to connect a signal to a slot on a different thread when signal/slot argument contains a QFlags...
first of all... is this possible at all ?
I'm declaring my flags as usual, with
Q_DECLARE_FLAGS (ACTRLFLAGS, ACTRLFLAG)
and
Q_DECLARE_OPERATORS_FOR_FLAGS( NMyClass::ACTRLFLAGS )
but this seems not enougth when the connection is (queued) between threads... then I've try registering the type with
Q_DECLARE_METATYPE(NMyClass::ACTRLFLAGS)
and
qRegisterMetaType<NMyClass::ACTRLFLAGS>();
but even if I don't see anymore an error regarding the connection at run-time, it simply doesn't work... my slot is not called at all...
any ideas ?
thanks in advance
Giampaolo
[Added code tags ~kshegunov]
-
Hi,
IIRC, you need to also provide the QDataStream operators for your flags and register them with qRegisterMetaTypeStreamOperators so they can be serialised in QVariant.
-
Hello SGaist...
just for a test, I've replaced my QFlags with a plain int... and it doesn't work.... so the problem must be elsewhere...
I'll try again tomorrow :D :D :D
Best Regards Giampaolo
-
@iw2lsi Does it work in the same thread?
-
@iw2lsi Show us the code for the signal, slot, and where you connect one to the other.
And if possible the code for the thread start and creation.
-
@iw2lsi said in Passing QFlags between threads:
qRegisterMetaType<NMyClass::ACTRLFLAGS>();
but even if I don't see anymore an error regarding the connection at run-time, it simply doesn't work... my slot is not called at all...
Depending on how you do the signal-slot connection and/or slot call you may need to adjust this line. Please show us the code for that as @ambershark mentioned.
-
Hi all,
first of all, thanks for the support and sorry for the delay...
The problem was in my receiver thread... basically my consumer process was blocking the event loop in a waitcondition, and that's why I was not receiving the signals... Nothing was wrong in the way my QFlags was registered on the meta-object system...
thanks again, Giampaolo