Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. One puzzling thing with cloasing widgets

One puzzling thing with cloasing widgets

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kaluss
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

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

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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 ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • A Offline
          A Offline
          ambershark
          wrote on last edited by
          #4

          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().

          My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved