QT Timer Timeout
-
wrote on 24 Aug 2020, 05:58 last edited by
I am trying to execute below code
QTimer test;
QObject::connect(test, SIGNAL(timeout()), this, SLOT(testSlot()));test->start(3000);
I want that my slot should execute immediately after start then after 3000ms it should execute.
But currently what is happening slot is executing after 3000ms.Is there any way to solve it ?
-
I am trying to execute below code
QTimer test;
QObject::connect(test, SIGNAL(timeout()), this, SLOT(testSlot()));test->start(3000);
I want that my slot should execute immediately after start then after 3000ms it should execute.
But currently what is happening slot is executing after 3000ms.Is there any way to solve it ?
@Ayush-Gupta said in QT Timer Timeout:
I want that my slot should execute immediately after start then after 3000ms it should execute.
I don't understand this. Your code is doing exactly what you asked it to do: call slot after 3000ms timeout. So, what do you want to do? Do you want to execute it after test->start(3000); and then second time after 3000ms timeout? if so, why not simply:
QTimer test; QObject::connect(test, SIGNAL(timeout()), this, SLOT(testSlot())); test->start(3000); testSlot();
?
-
@Ayush-Gupta said in QT Timer Timeout:
I want that my slot should execute immediately after start then after 3000ms it should execute.
I don't understand this. Your code is doing exactly what you asked it to do: call slot after 3000ms timeout. So, what do you want to do? Do you want to execute it after test->start(3000); and then second time after 3000ms timeout? if so, why not simply:
QTimer test; QObject::connect(test, SIGNAL(timeout()), this, SLOT(testSlot())); test->start(3000); testSlot();
?
wrote on 24 Aug 2020, 06:06 last edited by@jsulm Yes that is great idea.. It did not came to my mind. Thanks.
1/3