Results 1 to 2 of 2

Thread: Signals and Slots Across Threads

  1. #1
    Join Date
    Oct 2007
    Posts
    6
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Signals and Slots Across Threads

    Hi,

    I'm developing an application which requires an object (lets call this object A) which will lay dorment until one of it's methods are called. This object should then execute the method within it's thread, not in the thread of the calling object.

    My understanding is that this is possible by using queued signal connections but I would just like some clarification that I understand exactly how this will happen...

    As I understand it, by implementing the methods as slots the other objects will be able to emit signals which will not execute the slot directly, instead the slot will be executed by object A's thread as soon as control is passed back to that thread. So... Does this mean that I could have the following in the A::run() method and still have the other methods executed by this thread when they are called via signals?

    Qt Code:
    1. void A::run()
    2. {
    3. forever {
    4. sleep(10000);
    5. }
    6. }
    To copy to clipboard, switch view to plain text mode 

    I assume that this will keep the thread alive and just use it to execute any slots called.

  2. #2
    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: Signals and Slots Across Threads

    Please read DevDays2007-Threading.pdf starting from page 33. The QThread object itself lives in the thread it was created in, not in the thread which is executed in QThread::run().
    J-P Nurmi

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

    themusicalguy (29th October 2007)

Similar Threads

  1. signals and slots in plugins
    By anderl in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2007, 13:57
  2. Signals and Slots question
    By Thoosle in forum Qt Programming
    Replies: 5
    Last Post: 5th December 2006, 00:24
  3. Connecting signals & slots across different threads
    By jyoti kumar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 12:40
  4. Problem with Signals and Slots
    By Kapil in forum Newbie
    Replies: 11
    Last Post: 15th February 2006, 11:35
  5. [QT4] threads, signals, and slots, please help.
    By ucntcme in forum Qt Programming
    Replies: 12
    Last Post: 25th January 2006, 14:23

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.