One puzzling thing with cloasing widgets



  • Hello masters of Qt,
    can anybody explain me following situation:

    QApplication a(argc, argv);

    myDialog dialog;
    dialog.show();
    dialog.close()
    return a.exec();

    After this operation qApp is still running.
    After some while I solve this situation with creating my own closing function which looks like:
    void myClose(){ QMetaObject::invokeMethod( this, "close", Qt::QueuedConnection ); }

    Why first way It's not working properly?
    What the difference?

    BR
    Tomek



  • What do you mean by still running ? a.exec() is blocking call. So it will continue to exist till you stop/kill your application.


  • Lifetime Qt Champion

    Hi,

    @
    myDialog dialog;
    dialog.show(); << "showing dialog"
    dialog.close() << "closing dialog"
    << your dialog is already closed here
    return a.exec();
    @

    What are you trying to achieve ?


  • Moderators

    If you meant why is the app still running then that is because like SGaist said you aren't ever exiting the application.

    If you wanted the app to exit when the dialog closed you could do:

    @
    QApplication a(argc, argv);

    myDialog dialog;
    dialog.exec();
    return 0;
    @

    Or you could just override the close of your dialog to call app.quit(); And you could also try setting this (although I'm not sure it works with dialogs, never tested it):

    @
    QApplication a(argc, argv);
    a.setQuitOnLastWindowClosed(true); // this will close the app after

    myDialog dialog;
    dialog.show();

    return a.exec();
    @

    With the above approach though I don't think it will work if you call dialog.close() before you call a.exec().


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.