Results 1 to 8 of 8

Thread: QApplication shut down problem

  1. #1
    Join Date
    Sep 2008
    Posts
    25
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QApplication shut down problem

    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.

    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?

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QApplication shut down problem

    did u try winEventFilter()? also try using setQuitOnLastWindowClosed(bool).

  3. #3
    Join Date
    Sep 2008
    Posts
    25
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QApplication shut down problem

    Quote Originally Posted by talk2amulya View Post
    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.

  4. #4
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QApplication shut down problem

    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.

  5. #5
    Join Date
    Sep 2008
    Posts
    25
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QApplication shut down problem

    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.

  6. #6
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QApplication shut down problem

    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.

  7. #7
    Join Date
    Sep 2008
    Posts
    25
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QApplication shut down problem

    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.

  8. #8
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QApplication shut down problem

    i think u'll only have to build QtCore lib..anyways, ur call

Similar Threads

  1. Problem in using QHttp with QTimer
    By Ferdous in forum Newbie
    Replies: 2
    Last Post: 6th September 2008, 12:48
  2. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  3. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  4. Problem with mixed statically/shared Qt
    By WinchellChung in forum Newbie
    Replies: 2
    Last Post: 21st June 2007, 17:04
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.