Results 1 to 6 of 6

Thread: Qt::QueuedConnection and passing by Reference

  1. #1
    Join Date
    Jan 2006
    Location
    germany
    Posts
    75
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Qt::QueuedConnection and passing by Reference

    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!
    Quote Originally Posted by Bertolt Brecht
    What is the robbing of a bank compared to the founding of a bank?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt::QueuedConnection and passing by Reference

    Quote Originally Posted by soul_rebel View Post
    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.

  3. #3
    Join Date
    Jan 2006
    Location
    germany
    Posts
    75
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Qt::QueuedConnection and passing by Reference

    Quote Originally Posted by wysota View Post
    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"...
    Quote Originally Posted by Bertolt Brecht
    What is the robbing of a bank compared to the founding of a bank?

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Qt::QueuedConnection and passing by Reference

    Quote Originally Posted by soul_rebel View Post
    Object::connect: No such slot QToolButton::setText(QString)
    Object::connect: (receiver name: 'bInst')
    Right, QAbstractButton::setText() is not a slot but a "normal function".
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    soul_rebel (11th November 2007)

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt::QueuedConnection and passing by Reference

    Of course you can subclass the button and declare that method a slot.

  7. #6
    Join Date
    Jan 2006
    Location
    germany
    Posts
    75
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Qt::QueuedConnection and passing by Reference

    yep, I'll do that!
    Quote Originally Posted by Bertolt Brecht
    What is the robbing of a bank compared to the founding of a bank?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.