Results 1 to 3 of 3

Thread: WA_QuitOnClose weird in Qt5 ?

  1. #1
    Join Date
    Jan 2006
    Location
    Knivsta, Sweden
    Posts
    153
    Thanks
    30
    Thanked 13 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default WA_QuitOnClose weird in Qt5 ?

    I'm having problems with this simple program:

    Qt Code:
    1. #include <QApplication>
    2. #include <QLabel>
    3.  
    4. int main( int argc, char **argv )
    5. {
    6. QApplication app( argc, argv );
    7.  
    8. QLabel *lab = new QLabel("Very important Main Window");
    9. lab->setAttribute(Qt::WA_QuitOnClose, true);
    10. lab->show();
    11.  
    12. QLabel *lab2 = new QLabel("less important auxilliary window");
    13. lab2->setAttribute(Qt::WA_QuitOnClose, false);
    14. lab2->show();
    15.  
    16. app.setQuitOnLastWindowClosed(true);
    17.  
    18. return app.exec();
    19. }
    To copy to clipboard, switch view to plain text mode 

    The idea is that there are two windows. One important and one less important. The application is supposed to quit when the last "important" window is closed.
    When run in Qt4, the program behaves the way I want it to: when I close the "important" window the app quits regardless of whether the less important windows was alive then.

    In Qt5 things go differently:

    1. close less important window
    2. close important window
    3. --> app exits : OK

    1. close important window
    2. (app doesn't exit)
    3. close less important window
    4. (app still doesn't exit)

    The documentation for WA_QuitOnClose and setQuitOnLastWindowClosed() seems to be unchanged between Qt4 and Qt5.
    So is there a bug in Qt5 or have I misunderstood these attributes?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: WA_QuitOnClose weird in Qt5 ?

    I don't know why this happens yet, but with your code there is no signal-slot connection in the application object between lastWindowClosed() and quit(). If you add that connection manually then everything works as expected.

    Edit: Yeah, I think there is a bug in QApplicationPrivate::shouldQuit(). It calls QGuiApplication::shouldQuit() which will prevent quitting if there are any visible windows.
    Last edited by wysota; 24th March 2013 at 10:21.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2006
    Location
    Knivsta, Sweden
    Posts
    153
    Thanks
    30
    Thanked 13 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: WA_QuitOnClose weird in Qt5 ?

    Adding the signal as you suggested works, thanks.

Similar Threads

  1. Weird problem
    By CactusPie in forum Newbie
    Replies: 2
    Last Post: 23rd November 2012, 21:37
  2. weird weird mingw32-make
    By KillGabio in forum Qt Programming
    Replies: 19
    Last Post: 20th January 2012, 20:09
  3. Qt Creator always weird
    By giusepped in forum Qt Programming
    Replies: 4
    Last Post: 25th July 2011, 14:59
  4. Weird bug with SQLite
    By RavenS in forum Qt Programming
    Replies: 3
    Last Post: 28th March 2009, 17:45
  5. weird error
    By mickey in forum General Programming
    Replies: 6
    Last Post: 18th November 2006, 04:22

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.