PDA

View Full Version : QApplication shut down problem



gsmiko
7th April 2009, 11:59
Greetings!

I have encountered a very strange problem during shutdown, while the application was still runing.
The QApplication instance won't exit from the main event loop when the pc shuts down.
A proper way to exit from the event loop is a must in my case, because otherwise the post process routines won't be called.
So I have created an event filter and installid it using
QApplication::setEventFiler( EventFilter filter), and I was able to catch the WM_QUERYENDSESSION and WM_ENDSESSION events, and tried to exit from the event loop there using
QApplication::quit() and QApplication::exit() functions, but neither of them worked. So I tried to delete the qApp instance, but that way the application won't terminate regularly either. :confused:

It seems to be a bug in Qt. I'm using version 4.4.3. under WinXP and VS2008.
Have anyone found a workaround to this problem?

talk2amulya
7th April 2009, 13:12
did u try winEventFilter()? also try using setQuitOnLastWindowClosed(bool).

gsmiko
7th April 2009, 13:22
did u try winEventFilter()? also try using setQuitOnLastWindowClosed(bool).

I was able to catch these windows events with the event filter function, that part already works. the problem is that I can't force the the main event loop to quit. I can't even debug it with VS because we're talking about shutting down the pc.

the quitOnLastWindowClosed property is true by default, but I have also tried to call setQuitOnLastWindowClosed(true), just to be sure. But I had no luck.

talk2amulya
7th April 2009, 20:22
so u r saying that exit is called but event loop isnt exiting..thats not possible..either operating system just kills the process or exit isnt called when u r trying to call it..in either case, i think its acceptable that when u r shutting down system and app is running, user risks losing "important" data..u cant get special privileges from operating system when its shutting down i believe..if that can happen, let the forum be updated..otherwise, dont lose your sleep over the fact that your app doesnt get out of event loop on shutting down of SYSTEM.

gsmiko
7th April 2009, 21:22
I'm sure that exit() is called because I have placed log messages before and after every single function call.
The operating system will kill the process in case the application can't exit on it's own. You're right, the user risks loosing important data, the post routines won't be called which were added with qAddPostRoutine(), the class destructors won't be called either.
My case is somewhat special, because when the user closes the main window, the application minimizes to the tray, so it will continue running in the background. I can't expect that the user will exit from the application before he/she shuts down the system.
The tray feature should stay, I can't avoid it. I'm not the one who makes these kind of decisions, I'm "just" a programmer.
off: It would make an interesting new thread to discuss why do designers make critical decisions instead of programmers. :D

talk2amulya
7th April 2009, 21:49
that would definitely make a hit thread ;) to that we can add why are all testers not developers but dumb-minded jerkatrons!! anyhoo, discussion on that would require a couple of beers..so moving on..a bold suggestion if u will..why dont u add logging information inside QCoreApplication::exit(int)..it has a loop where its exiting from all event loops..log that information..then u can get a clear picture of whats happening..cuz if that function exits properly, all events are destined to have exited.

gsmiko
8th April 2009, 06:52
Thanks for the suggestion, it's not a bad idea, but it kind of sucks. Because then I have to rebuild Qt libs, which isn't a 5 minute process. So I will wait and see, I hope that someone already had this kind of problem and solved it.
I've noticed another interesting thing, when the exit() gets called, qApp emits the aboutToQuit signal, but it doesn't actually quits as I said before.

talk2amulya
8th April 2009, 06:58
i think u'll only have to build QtCore lib..anyways, ur call ;)