7

The problem is as follows: if the application is closed while it's not actively doing anything, it exits correctly. If it's actively working on something (waiting in a while loop, for example), however, the main window will close but the program will continue to run in the background, as confirmed by opening the task manager.

I've spent a good part of today googling the problem and implementing possible fixes, but to no avail. It seems like the quit() function simply doesn't do anything. Here are some things that I've tried:

  • Using app.connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));. I know the signal is triggered, because I tried changing &app, SLOT(quit()) to qApp, SLOT(aboutQt()) and the aboutQt window briefly popped up.
  • Including qApp->quit(); at the beginning of a function that runs from a main window button. The application does run to that line, but it has no effect.
  • Using processEvents() to make sure the GUI is being updated.
  • Including statements like mainWindow.setAttribute(Qt::WA_QuitOnClose); in main.cpp.

I just want the application to completely exit when the main window is closed.

I'm using the qextserialport library, if that makes any difference.

László Papp
  • 51,870
  • 39
  • 111
  • 135
SharpHawk
  • 378
  • 7
  • 19
  • Is your application multithread? – Lol4t0 Jan 12 '12 at 12:27
  • I'm not personally creating threads, but I'm not sure if the library I'm using is. If I open up the debugger and look under threads I'll see a bunch of "ntdll!ldrFindResourceEx_U" functions. I only see one instance of my program in the task manager processes, though. PS: Why the hell would pressing enter send the message instead of creating a linebreak? – SharpHawk Jan 12 '12 at 15:21
  • Then your main thread may wait those threads to finish their work. It can be done implicitly, for example, destructors of objects may wait for thread to finish. You should study your library code. PS `qextserialport`, as far as I know does not create any threads. – Lol4t0 Jan 12 '12 at 15:26

1 Answers1

1

I don't know what's wrong, but as your slot actually receives the signal, you can call exit() from that slot function as a workaround.

ypnos
  • 50,202
  • 14
  • 95
  • 141
  • I think it is a bad solution, because if application process something in another thread, after such a termination, TS can get some data corrupted – Lol4t0 Jan 12 '12 at 12:25