Results 1 to 10 of 10

Thread: SignalSlot Connection across the threads

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2013
    Posts
    5
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default SignalSlot Connection across the threads

    Hi All,

    I have a query here.I am new to Qt.In my application i have multiple threads running.I want to make a signal slot connection in one of my thread ,so that whenever i that signal i s emitted the slot present in another thread is called.How to achieve it.can you give me an example so that i can refer.?
    Please help me out.

  2. #2
    Join Date
    Dec 2012
    Posts
    90
    Thanks
    5
    Thanked 20 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SignalSlot Connection across the threads

    Do it like you you'd done it with conventional slots/signals, Qt::AutoConnection will do the rest.
    From the docs:
    (default) If the signal is emitted from a different thread than the receiving object, the signal is queued, behaving as Qt::QueuedConnection. Otherwise, the slot is invoked directly, behaving as Qt::DirectConnection. The type of connection is determined when the signal is emitted.
    http://doc.qt.digia.com/qt/qt.html#ConnectionType-enum

  3. #3
    Join Date
    Jan 2013
    Posts
    5
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: SignalSlot Connection across the threads

    My case is like,I have a thread controller which has a timer running. Whenever the timeout occurs the timeout signal is emitted.the timeout signal is connected to a slot named check() in another thread controller. I am making the connection of this signal and slot inside one of the virtual function of my first thread controller.

    CONNECTSIGNALSLOT(&m_HeartbeatCheckTimer, timeout(), &mp_HeartBeatManagerThreadController, HeartbeatCheck());

    It is showing me error as

    error: no matching function for call to 'Threads::MasterThreadController::connect(QTimer*, const char*, HeartBeatManager::HeartBeatManagerThreadController **, const char*)'

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: SignalSlot Connection across the threads

    Remove the '&' for the third parameter..
    Qt Code:
    1. //CONNECTSIGNALSLOT(&m_HeartbeatCheckTimer, timeout(), &mp_HeartBeatManagerThreadController, HeartbeatCheck());
    2. CONNECTSIGNALSLOT(&m_HeartbeatCheckTimer, timeout(), mp_HeartBeatManagerThreadController, HeartbeatCheck()); //note the missing &
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. #5
    Join Date
    Jan 2013
    Posts
    5
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: SignalSlot Connection across the threads

    Thanks for your reply.
    But still i m getting the same error..

  6. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: SignalSlot Connection across the threads

    What is Threads in you code, show the class definition.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  7. #7
    Join Date
    Jan 2013
    Posts
    5
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: SignalSlot Connection across the threads

    Hi ,

    I have a doubt.In my master thread i m creating rest all threads and starting them.all other threads will be sending me heartbeat packets to show they are alive.I have one thread specifically to monitor this heart beat packets.I will check the number of heart beat packets sent and received. so i will be creating a slot in my hear beat check thread to monitor the heart beat packets.so my question is where should i make the connection for signal and slot (in my master thread controller or heartbeat controller)?

  8. #8
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: SignalSlot Connection across the threads

    I will suggest to make connections from the same where you create the threads, i.e. rigth after creating the thread.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  9. #9
    Join Date
    Jan 2013
    Posts
    5
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: SignalSlot Connection across the threads

    Ok..Thankyou

  10. #10

    Default Re: SignalSlot Connection across the threads

    Thank you for sharing your information.......................................

Similar Threads

  1. Threads and database connection
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 7th August 2013, 09:30
  2. Replies: 0
    Last Post: 11th November 2011, 20:18
  3. Qt Threads vs Native Threads performance
    By StackOverflow in forum Qt Programming
    Replies: 1
    Last Post: 14th November 2010, 13:14
  4. Replies: 1
    Last Post: 2nd April 2010, 07:42
  5. SQLite connection shared by several threads
    By jorgegarciar in forum Qt Programming
    Replies: 1
    Last Post: 23rd August 2009, 21:15

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.