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.
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:
Quote:
(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
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*)'
Re: SignalSlot Connection across the threads
Remove the '&' for the third parameter..
Code:
//CONNECTSIGNALSLOT(&m_HeartbeatCheckTimer, timeout(), &mp_HeartBeatManagerThreadController, HeartbeatCheck());
CONNECTSIGNALSLOT(&m_HeartbeatCheckTimer, timeout(), mp_HeartBeatManagerThreadController, HeartbeatCheck()); //note the missing &
Re: SignalSlot Connection across the threads
Thanks for your reply.
But still i m getting the same error..:(
Re: SignalSlot Connection across the threads
What is Threads in you code, show the class definition.
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)?
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.
Re: SignalSlot Connection across the threads
Re: SignalSlot Connection across the threads
Thank you for sharing your information.......................................