One question about the execution of the slot function
Hi guys,
I have a class Test, and there is one normal function funcA(), and a slot function slot():
void Test::funcA()
{
if(m_index != 2)
{
//---------------- interrupt
//DO SOMETHINS
}
}
slot:
void Test::slot()
{
m_index = 2;
}
And now I have a question, If when I call function funcA(), and there is a signal which associate with slot: slot() emited, just after execute "if(m_index != 2)" and enter the if state, will the funcA() be interrupted at "---------------- interrupt" and begin to run slot()? if yes, there will be a unpredictable fault!
Thanks for your suggestions!
Re: One question about the execution of the slot function
Only when the function and the slot are executed in separate threads. In this case, you need to ensure synchronization ie. with QMutex.
Re: One question about the execution of the slot function
Even if signal is emitted from separate thread, the slot() will not execute untill thread running funcA() will return to the event loop.
And as far as I know there's no way to put two functions of the same object in separate threads :)
Re: One question about the execution of the slot function
Quote:
Originally Posted by
Spitfire
Even if signal is emitted from separate thread, the slot() will not execute untill thread running funcA() will return to the event loop.
And as far as I know there's no way to put two functions of the same object in separate threads :)
Of course You can. QObject::connect method have parameter Qt::ConnectionType. You can create direct connection between two threads. Then slot is executed immediately. Not discuss whether it makes sense but it is possible.