PDA

View Full Version : SignalSlot Connection across the threads



shruti
30th January 2013, 12:54
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.

lanz
30th January 2013, 13:46
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

shruti
30th January 2013, 14:09
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*)'

Santosh Reddy
30th January 2013, 14:47
Remove the '&' for the third parameter..

//CONNECTSIGNALSLOT(&m_HeartbeatCheckTimer, timeout(), &mp_HeartBeatManagerThreadController, HeartbeatCheck());
CONNECTSIGNALSLOT(&m_HeartbeatCheckTimer, timeout(), mp_HeartBeatManagerThreadController, HeartbeatCheck()); //note the missing &

shruti
30th January 2013, 15:39
Thanks for your reply.
But still i m getting the same error..:(

Santosh Reddy
30th January 2013, 16:03
What is Threads in you code, show the class definition.

shruti
31st January 2013, 13:16
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)?

Santosh Reddy
31st January 2013, 13:35
I will suggest to make connections from the same where you create the threads, i.e. rigth after creating the thread.

shruti
31st January 2013, 16:10
Ok..Thankyou:)

brand33
29th March 2013, 10:30
Thank you for sharing your information.......................................