Murtaza
Murtaza

Reputation: 33

Calling a function repeatedly using timer

I am calling a function foo() continuously every second that checks the serial connection ,

Now my question is that what happens if one second passes and the function foo() is not completed the previous time it was called,will the previous function get executed first or will it get suspended etc

checkConnection =new QTimer(this);
checkConnection->start(1000);
connect(checkConnection, SIGNAL(timeout()), this, SLOT(foo()));

Upvotes: 1

Views: 93

Answers (1)

paxdiablo
paxdiablo

Reputation: 882586

From the documentation at https://doc.qt.io/qt-5/qtimer.html:

All timer types may time out later than expected if the system is busy or unable to provide the requested accuracy. In such a case of timeout overrun, Qt will emit timeout() only once, even if multiple timeouts have expired, and then will resume the original interval.

So it seems that only one timer event will exist in the queue at any one time.

That would mean your currently executing callback can take several seconds to complete and there would only be one queued in the meantime.

Upvotes: 2

Related Questions