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. QMainWindow misses close event messages from Windows Taskbar
Forum Updated to NodeBB v4.3 + New Features

QMainWindow misses close event messages from Windows Taskbar

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 4.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.
  • F Offline
    F Offline
    fscibilia
    wrote on last edited by
    #1

    Hi all,

    I have a Qt application and use closeEvent of QMainWindow. The strange thing is that, while all click events are correctly generated when the user clicks on the x in the QMainWindow to close the application, not all clicks (about 50%) are intercepted if I close the application through the "close window" action available in the MS Windows taskbar down in the screen (where you can pin/unpin programs). I really do not understand why...

    Has anyone had this issue to challenge ?

    This is the code (very simple)

    @
    void MyMainWindow::closeEvent(QCloseEvent *event)
    {
    qDebug() << "close event";
    workspace_->save() ? event->accept() : event->ignore();
    }
    @

    The string "close event" confirms what stated above.
    If I remove this code, everything works.

    Thanks
    Fabio

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

      Hi,

      There's something not clear here, do you mean that when you click on "close window", closeEvent is never called or it's called from time to time ?

      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
      • F Offline
        F Offline
        fscibilia
        wrote on last edited by
        #3

        Hi SGaist,

        When I click "close window" on the taskbar, sometimes it is called, sometimes not.
        When I close using the x button on the corner of the windows, it is always called (as expected).

        Strange...

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

          Could you find a pattern for that like e.g. doesn't work when hidden etc. ?

          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
            arsinte_andrei
            wrote on last edited by
            #5

            yep I had something like that into my Qt on Linux Kubuntu 14.04. As far as i remember it was a pointer problem (undetected sigpipe) difficult to find it but after spending a lot I've found it in my main.cpp I will inform you as soon as I'll find it.. I have saved some info about this somewhere. happened only on Linux - I do not remember if in windows too

            1 Reply Last reply
            0
            • A Offline
              A Offline
              arsinte_andrei
              wrote on last edited by
              #6

              have a look "here":http://qt-project.org/forums/viewthread/45163/
              All credit to SGaist
              hope this will help you

              1 Reply Last reply
              0
              • F Offline
                F Offline
                fscibilia
                wrote on last edited by
                #7

                Thanks guys,

                I have more details. When I try to close from taskbar (win7, qt5.3), even if closeEvent is not generated, the window takes focus anyway and a beep signal is emitted (the same beep on windows when your are trying to close while some dialog is waiting for input from the user). This is strange cause I do not have any dialog.

                I will investigate more and let you know.

                Thanks
                Fabio

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  fscibilia
                  wrote on last edited by
                  #8

                  Hi all,

                  After one morning of tests, I discovered what happens (not why):
                  In my application I have a QMdiArea with MdiDocumentViewer that inherits QMdiSubwindow. Looking at event polling, I tracked events:
                  When you close the main window, first some events are sent to all internal widgets of the QMdiArea to change their state, and then, in case of success, the QMainWindow.closeEvent is actually invoked.

                  I discovered that the invocation of MdiDocumentViewer.event when event is QWindowStateChange event (invoked just before QMainWindow.closeEvent) sometimes fails (the result of event->isAccepted() is false), sometimes not. At the moment it is absolutely random (I simply try to close more and more times until it successes).

                  Really don't know why.

                  Thanks

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

                    Strange indeed… Which version of Windows and Qt ?

                    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
                    • F Offline
                      F Offline
                      fscibilia
                      wrote on last edited by
                      #10

                      Hi SGaist,

                      After tracking MS windows events. I checked that closing from task ber gets the WindowStataChange(WindowActive) event raised that, in turn, at some point of my code, invokes QClipboard::text(). The latter method invocation makes the WindowStateChange message rejected (strangely) . Commenting the latter invocation, everything works well. So, now the question is: why QClipboard::text() invoked inside the MSWin event dispatching loop works in this way? Of couser, QClipboard interacts with the MSWindows clipboard. IMHO it is a Qt bug.

                      Anyway I solved it simpling putting that QClipboard invocation somewhere else.

                      Fabio

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

                        There might be something up. You should have a look at the "bug report system":http://bugreports.qt-project.org to see if something like that has already been reported. If not, please consider opening a new report providing a minimal compilable example showing how to reproduce the behavior.

                        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

                        • Login

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