QStringList in QObject::connect
Hello,
I'm trying to pass a QStringList using the signal slot, but when I try to use the QStringList in the slot it contains garbage (and exceptions). I set up the "connect" call to use QStringList* because otherwise the connect call fails.
Code:
m_pkr_receiver_class,
Qt::QueuedConnection);
I then tried the following as well:
Code:
SIGNAL(removeGamesSignal (int, QStringList& )),
m_pkr_receiver_class,
SLOT(invokeGamesRemoval (int, QStringList& )),
Qt::QueuedConnection);
This does not work, the error says:
QObject::connect: Cannot queue arguments of type 'QStringList&'
When I use Qt:: DirectConnection with the 'QStringList&' signature the QObject::connect suceeds.:confused:
It is possible to send a QStringList using a signal and Qt::QueuedConnection?
Thanks,
DP
Re: QStringList in QObject::connect
With queued connections, the parameters must be of types that are known to Qt's meta-object system (basically those understood by QVariant), because Qt needs to copy the arguments to store them in an event behind the scenes.
call qRegisterMetaType() to register the data type before you establish the connection.
Re: QStringList in QObject::connect
Quote:
Originally Posted by munna
With queued connections, the parameters must be of types that are known to Qt's meta-object system (basically those understood by QVariant), because Qt needs to copy the arguments to store them in an event behind the scenes.
call
qRegisterMetaType() to register the data type before you establish the connection.
Thanks Munna,
There is no problem with doing this to Qt types (i.e. QStringList), this will not cause a conflict?
Code:
qRegisterMetaType<QStringList>("QStringList");
Re: QStringList in QObject::connect
Quote:
Originally Posted by DPinLV
There is no problem with doing this to Qt types (i.e. QStringList), this will not cause a conflict?
I don't think so. Give it a try.
Re: QStringList in QObject::connect
...and the same issue has already been solved in thread: QStringList with Signal/Slot.
Re: QStringList in QObject::connect
Essentially you can't pass non-const references to a queued connection (as it doesn't make any sense). You'd have to use const QStringList& instead (but you wouldn't be able to change its contents). Using pointers is tricky too, because only a pointer is copied when the signal is emitted. If "in the meantime" (before the slot is executed) you delete the object, you'll end up with an invalid pointer and a possible segfault.
Re: QStringList in QObject::connect
Thanks, I noticed there was an existing thread when I received my subscriber email from QT regarding this thread. After looking at the existing thread on this subject I was able to get it working. I use the following which succeeds:
Code:
qRegisterMetaType<QStringList>("QStringList");
SIGNAL(removeGamesSignal (int, const QStringList& )),
m_pkr_receiver_class,
SLOT(invokeGamesRemoval (int, const QStringList& )),
Qt::QueuedConnection);
I did not try the QVariant option mentioned in the previous thread since it seems like a matter of personal preference. If anyone disagrees please let me know why.
Quote:
Originally Posted by wysota
Essentially you can't pass non-const references to a queued connection (as it doesn't make any sense). You'd have to use const QStringList& instead (but you wouldn't be able to change its contents). Using pointers is tricky too, because only a pointer is copied when the signal is emitted. If "in the meantime" (before the slot is executed) you delete the object, you'll end up with an invalid pointer and a possible segfault.
Thanks for the explanation of what is going on under the covers with signals I appreciate that. I'm trying to learn what the Signals/Slots are doing as far as when they copy data, etc.
Thanks, wysota, jpn, and munna.