0

Qt timer timeout

Hi I have a main event loop in Qt application. If at any point , I create a qtimer object and connect it's timeout signal to a slot called ABC. (Code Line number assume as 100) Next line of code is to start it with interval as 100 ms and set it as one shot.(Code line 101) Some basic Computation which is independent of qt (Code line 102) Some code which depends on Qt (code line 103) In this regard , I have a question as below: Question 1 : When slot ABC is executed ? As soon as line 100 is hit ? Obviously no if qt is busy. But yes if qt action is not busy. Is this true ? Question 2 : What is the need of set interval and start it with 100 ms.? Is this time allowed to complete the ABC slot or 100 ms is the time it will wait to start executing ABC slot ? Question 3: what ever is the case of 100 ms in Questio 2, will entire main code is blocked at line 102 or 103 or it will be ended irrespective of waiting for completion of ABC slot ?

4th Mar 2025, 10:39 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
3 Answers
+ 1
Thanks Amine Laaboudi I have a doubt about the 100 ms. ABC will start execution when timeout signal is Emmited. Timeout is Ideally emited when event loop is not beasy. Let us call this time at t1. So 100 ms means execution will start after t1 + 100 time point. Is this true ?
5th Mar 2025, 2:27 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
no, the slot will only be executed when the timer actually times out. and if the qt event loop is busy, the timer event will be queued and processed when the event loop becomes available. the timer will wait for 100 ms before attempting to execute the slot. the 100 s interval is the time the timer will wait before emitting the timeout signal, which will then trigger the execution of ABC. The main code will not be blocked, and will continue executing regardless of whether the slot ABC has been executed or not.
5th Mar 2025, 1:19 PM
Amine Laaboudi
Amine Laaboudi - avatar
0
hm approximately yes, so we could say ABC will start execution at tx >= t1+100ms if I'm not mistaking
5th Mar 2025, 3:00 PM
Amine Laaboudi
Amine Laaboudi - avatar