QT Timer Timeout
-
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();
?
@jsulm Yes that is great idea.. It did not came to my mind. Thanks.