PDA

View Full Version : Qt::QueuedConnection and passing by Reference



soul_rebel
6th November 2007, 15:56
I have a Worker Thread that emits a couple of "const QString&". This are connected to "setText(const QString&)"-slots in the Gui-Thread (Qt::QueuedConnection).
Now since the connection is queued the QString referenced to is actually stored in a "real" QString in the Event posted to Main (in case the referenced object is removed) and then passed by value, right ?

Because in the Slot it is actually received as a QString (not a QString&), which is not accepted by setText(const QString&).

Now I thought of two possibilites:
1) emit "real" QStrings straight away, which is bad because slots in the same eventloop are also connected (direct) and useless overhead is created.
2) catch the Signal in an extra slot that then calls setText(const QString&), which is bad because I have to write very very many extra slots :(

Anything else i can do?

Thanks!

wysota
6th November 2007, 16:23
Now since the connection is queued the QString referenced to is actually stored in a "real" QString in the Event posted to Main (in case the referenced object is removed) and then passed by value, right ?
Correct.


Because in the Slot it is actually received as a QString (not a QString&), which is not accepted by setText(const QString&).
Hmm... it should be accepted, because the reference is const. What is the exact error message you get?


1) emit "real" QStrings straight away, which is bad because slots in the same eventloop are also connected (direct) and useless overhead is created.
QString doesn't create any overhead. It's implicitly shared.

soul_rebel
6th November 2007, 16:33
Hmm... it should be accepted, because the reference is const. What is the exact error message you get?Object::connect: No such slot QToolButton::setText(QString)
Object::connect: (receiver name: 'bInst')

QString doesn't create any overhead. It's implicitly shared. Hm thats right... However imo another solution would be "cleaner"...

jpn
6th November 2007, 16:37
Object::connect: No such slot QToolButton::setText(QString)
Object::connect: (receiver name: 'bInst')

Right, QAbstractButton::setText() is not a slot but a "normal function".

wysota
6th November 2007, 16:41
Of course you can subclass the button and declare that method a slot.

soul_rebel
11th November 2007, 19:47
yep, I'll do that!