How to get out of infinite while loop by pressing esc in Qt?
while(1){
//doing some task
if(ESC_PRESSED)
break;
}
How to get out of infinite while loop by pressing esc in Qt?
while(1){
//doing some task
if(ESC_PRESSED)
break;
}
I have little experience with qt but in general I would guess that you have to register somewhere to recieve something like a ESCKeyPressedEvent
. When you recieve the event you would do something like this:
bool esc_was_pressed = false;
void on_esc_pressed(){
esc_was_presed = true;
}
and in your loop
while(!esc_was_pressed){
//doing some task
}
Actually I think you will just recieve a KeyPressedEvent
and have to do something like:
void on_key_pressed(KEY key){
if (key == ESC_KEY) esc_was_pressed = true;
}