PDA

View Full Version : QTimer doesn't expire



sattu
20th February 2014, 10:38
Hi Everyone,

I have 2 classes- ClassA and ClassB. ClassA has a signal called MySignal and ClassB has a slot called MySlot. And the connection is-

connect(ObjClassA ,SIGNAL(MySignal()), ObjClassB,SLOT(MySlot()), Qt::BlockingQueuedConnection);

ClassB has a timer called MyTimer which is connected to MyTimeoutSlot in the same class.
And MySlot is as follows-

void ClassB::MySlot()
{
MyTimer.start(2000); //2 secs
}

void ClassB::MyTimeoutSlot()
{
qDebug("MyTimer expired");
}


The scenario is such that MySignal is emitted continuously (synchronization is taken care of, I mean only after MyTimeoutSlot is finished executing then only next emission of MySignal happens). But what I observed is that sometimes MyTimer doesn't start or worst doesn't expire (I am not sure which among these two is happening).
Since QTimer is being started inside a slot whose connection type is BlockingQueuedConnection, is that causing an issue?
Has someone before encountered such issues wherein QTimer doesn't start or expire? :confused:

wysota
20th February 2014, 11:01
Is the event loop running during those 2 seconds?

sattu
20th February 2014, 11:15
Is the event loop running during those 2 seconds?
Yes, event loop is running as ClassB in my case is actually a QWidget class. When ever it receives some data in MySlot(), it displays them in the widget and then when timer expires, the widget is reset.

anda_skoa
20th February 2014, 13:43
Just to be sure: ObjClassA and ObjClassB live in different threads, right?


Cheers,
_

sattu
20th February 2014, 14:21
Just to be sure: ObjClassA and ObjClassB live in different threads, right?
Yes yes, both the objects are in different threads.
There are very high chances of some bug being present in my code and I am trying very hard to detect where the bug could be. Meanwhile I just wanted to know if there are possibilities of a QTimer not starting or not expiring. Can some condition arise wherein inspite of the event loop running QTimer doesn't function properly?

wysota
24th February 2014, 07:51
Yes yes, both the objects are in different threads.

Does each thread run its own event loop?