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. [Solved] QFileDialog::getOpenFileName breaks message boxes etc.
Forum Updated to NodeBB v4.3 + New Features

[Solved] QFileDialog::getOpenFileName breaks message boxes etc.

Scheduled Pinned Locked Moved General and Desktop
27 Posts 3 Posters 18.6k 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.
  • L Offline
    L Offline
    loladiro
    wrote on last edited by
    #21

    Yes, I meant QApplication::processEvent() is the problem here. Sorry if I was unclear. I'll reupload your example in two files, so that other people can see the problem.

    So: Problem with comment why (Please use this code for tests):
    http://dl.dropbox.com/u/32965023/bugTest/bugTest.pro
    http://dl.dropbox.com/u/32965023/bugTest/main.cpp
    http://dl.dropbox.com/u/32965023/bugTest/test.h

    EDIT: @Gerolf, yes see my previous comment as to why it happens
    EDIT2: Well yes, it might be a feature, but the problem is that QWidget removes that event again, as soon as another one gets created (If there's no processEvents in between. I think the same code should be added to native widgets

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #22

      Hi loladrio,

      this solves the issue:

      @
      app.setQuitOnLastWindowClosed(false);
      @

      No processEvents needed

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • L Offline
        L Offline
        loladiro
        wrote on last edited by
        #23

        Yes I know. My problem with the issue is more conceptual not practical. IMO, Qt should behave the same way independent of whether QFileDialog uses a native window or not. But in this point it doesn't.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          LinusA
          wrote on last edited by
          #24

          [quote author="Gerolf" date="1308943261"]
          This means, it's not a bug, it's a feature :-)[/quote]
          Wow, thank you so much!!! Best one-line-fix ever ;-)

          However, there is one strange thought left: Why do several standard dialogs show different behaviours? How come that message and input boxes will silently "go away", a QErrorMessage will "hang", and QFileDialogs won't be impressed at all by this QApplication::quitOnLastWindowClosed property (try it out, file dialogs are still working in that state).

          And then the differences in behaviour depending on which constructor you use and whether it's a native look or not -- that's just odd.

          But anyway, thanks again, huge relief for me. Solved!

          1 Reply Last reply
          0
          • L Offline
            L Offline
            loladiro
            wrote on last edited by
            #25

            This is part of the QWidget constructor: IMO, it should also be executed when constructing native windows.

            EDIT: Oops, forgot code
            @
            if (isWindow() || parentWidget()->isVisible()) {
            // remove posted quit events when showing a new window
            QCoreApplication::removePostedEvents(qApp, QEvent::Quit);
            @

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #26

              But QFileDialog with use native dialog opens a nativ windiows file dialog. This does not look at the Qt event loop.

              [quote author="loladiro" date="1308943850"]@
              if (isWindow() || parentWidget()->isVisible()) {
              // remove posted quit events when showing a new window
              QCoreApplication::removePostedEvents(qApp, QEvent::Quit);
              @[/quote]

              This is the close event. The signal quit is different and as it is in the same thread, it's executed directly.

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • L Offline
                L Offline
                loladiro
                wrote on last edited by
                #27

                No it's not and that on purpose so that if there is a brief period with no active widget, the event is remove again:
                @
                void QApplicationPrivate::emitLastWindowClosed()
                {
                if (qApp && qApp->d_func()->in_exec) {
                if (QApplicationPrivate::quitOnLastWindowClosed) {
                // get ready to quit, this event might be removed if the
                // event loop is re-entered, however
                QApplication::postEvent(qApp, new QEvent(QEvent::Quit));
                }
                emit qApp->lastWindowClosed();
                }
                }
                @

                EDIT: To explain (I'm sure @Gerolf, you know what this means, but now everybody reading this thread will), the close event on QApplication is one executed directly (which would be sendEvent()), but postponed until the eventLoop is run next, in order to give QWidget a chance to remove it again.

                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