Results 1 to 4 of 4

Thread: Can I pass data between threads with signal/slot, but without duplicating them?

  1. #1
    Join Date
    Mar 2013
    Posts
    28
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Can I pass data between threads with signal/slot, but without duplicating them?

    I have some big data to share between threads. While I don't want to use locks and unlocks everywhere, I chose the signal/slot pattern.
    The best way I can think of is like:
    Qt Code:
    1. emit updateData(const MyData &d)
    To copy to clipboard, switch view to plain text mode 
    But it's suggested that this avoids copying with DirectConnection but stills makes a copy with QueuedConnection. So what about BlockingQueuedConnection, which blocks and may work as a lock? If this is same with QueuedConnection for multi-thread, is there a way?
    Thanks in advance!

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

    Default Re: Can I pass data between threads with signal/slot, but without duplicating them?

    If this data is really to be const (in both threads) then you can just emit a pointer. Otherwise if any of the parties involved can modify the object, you will eventually have to use locks.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2013
    Posts
    28
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Can I pass data between threads with signal/slot, but without duplicating them?

    Quote Originally Posted by wysota View Post
    If this data is really to be const (in both threads) then you can just emit a pointer. Otherwise if any of the parties involved can modify the object, you will eventually have to use locks.
    The emitter can modify the data but the receiver won't. Adding const to the parameter just makes sure the slot won't modify the data. I think this is safe because as far as I know it will send a copy of the data to the slot, no matter if it's a reference.

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

    Default Re: Can I pass data between threads with signal/slot, but without duplicating them?

    Quote Originally Posted by hind View Post
    The emitter can modify the data but the receiver won't.
    Then you have to either make a copy or synchronize access.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. duplicate signal/slot connections check
    By positive_4_life in forum Newbie
    Replies: 6
    Last Post: 18th October 2011, 00:15
  2. Replies: 8
    Last Post: 25th June 2011, 11:14
  3. signal and slot across threads having event loop
    By travis in forum Qt Programming
    Replies: 6
    Last Post: 6th November 2007, 00:56
  4. Signal / Slot with specific argument and threads
    By tpf80 in forum Qt Programming
    Replies: 3
    Last Post: 15th September 2007, 00:43
  5. Replies: 2
    Last Post: 16th August 2007, 01:20

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.