PDA

View Full Version : Application doesn't reaaly close



zodd
8th July 2019, 15:57
Hello,

I noticed that if I close my application during a long task like "reading a big file, the GUI window close well but application only stop at the end of the reading. So I did some test, and if I do this:




void MYGUI::on_pushButton_ReadFile_clicked()
{
int i=0;
while(1)
{

i++;
qDebug() << "TEST" << i;
QCoreApplication::processEvents();
}
}


when I close the application by clicking on the cross on the upper right of my application window (on Windows 10), it close well the window, but the application still run in the task manager and I have to manually kill it in the task manager or in the cmd prompt with taskkill /IM myApp.exe /F.

Is someone has a clue to be sure to close the entire application when needed even if processing a "big task" please?

d_stranz
8th July 2019, 16:51
Clicking the "Close" (X) button on a top-level window's title bar closes the window, not the app unless QGuiApplication::quitOnLastWindowClosed() is true (the default). If you have background processing that does not allow control to return to the main Qt event loop - like your example code above - the close event will never be seen by the main event loop. Your infinite loop has in effect set up an internal event loop (just like a modal dialog) which handles its own events (but not events posted to the main event loop).

Your code above is a slot. The rule for Qt is that control does not return to the main event loop until a slot has finished executing. Since your slot never exits, the app can never exit.