Unsolved Have "Sleep()" on the bottom of the QTimer, cant exit app instantly.
-
Hello, I cant exit app instantly when have Sleep on the bottom of QTimer function. It closing after sleep finished.
void digging::startLoop() { check->start(1000); // Connected to "void digging::loop()" shutdown->start(200); // Connected to "void digging::wylacznik()" } void digging::wylacznik() { qDebug() << "off"; if(GetAsyncKeyState(0x78)){ leftUp(); abort(); } } void digging::loop() { qDebug() << "looped"; if(GetAsyncKeyState(0x77)){ enabled = true; } if(GetAsyncKeyState(0x78)){ leftUp(); abort(); } if(enabled){ if(!resized){ qDebug() << "resized"; resize(); resized = true; } sendCommand("/naprawkilof"); Sleep(500); leftDown(); Sleep(5000); // I want to wait a bit before start loop again, and be ready to exit app in random moment. } }
And what's the diffrence between QTimer start(x) and QTimer setInterval(x)?
-
Hi,
setInterval just sets the interval while start starts the timer with the given interval.
As for your use of sleep, it will block the event loop hence it can't process normally.
If you want to introduce different delays you should reconsider your design. Maybe use a state machine.