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. Is grabMouse undone when a top-level QWidget terminates?
Qt 6.11 is out! See what's new in the release blog

Is grabMouse undone when a top-level QWidget terminates?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 1.8k Views 2 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.
  • H Offline
    H Offline
    Harry123
    wrote on last edited by
    #1

    I have a large and complex application ported to Qt 5.7, where Qt problems are usually not reproducible in a small and simple test application.

    I believe that I found a case of grabMouse not being undone when a top-level QWidget terminates. The result is that mouse interaction becomes impossible in the whole application and only the keyboard works. It is possible that the problem only occurs when the QWidget is closed via the Close button (the X button on top-right of the border).

    I found the problem because in one test run, and one only, I got an error message for releaseMouse saying it is impossible for an invisible window. I theorize that when the X button is pressed, the window becomes invisible and the releaseMouse is ignored, so the application loses the usage of the mouse in favor of a no-longer existing widget.

    Abolishing all calls of grabMouse and releaseMouse in the application solved the problem.

    I do not post a bug report, since the details are too vague. But maybe some developer could think about it.

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

      hi
      As far as I know you must match the calls yourself.
      Not tested lately but when I used it,
      i had the impression that only when application is
      closed mouse is fully released.

      the doc states

      Warning: Bugs in mouse-grabbing applications very often lock the terminal. Use this function with extreme caution, and consider using the -nograb command line option while debugging.

      so I would not count on auto clean up.

      H 1 Reply Last reply
      2
      • mrjjM mrjj

        hi
        As far as I know you must match the calls yourself.
        Not tested lately but when I used it,
        i had the impression that only when application is
        closed mouse is fully released.

        the doc states

        Warning: Bugs in mouse-grabbing applications very often lock the terminal. Use this function with extreme caution, and consider using the -nograb command line option while debugging.

        so I would not count on auto clean up.

        H Offline
        H Offline
        Harry123
        wrote on last edited by Harry123
        #3

        @mrjj

        Agreed, but in this one case there might be a gotcha.

        mrjjM 1 Reply Last reply
        0
        • H Harry123

          @mrjj

          Agreed, but in this one case there might be a gotcha.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @Harry123

          hi , just made small test.

          If you new a Widget, let it grab and then delete it, the mouse is restored.
          So seems that delete will release.

          so I guess you hide a window while it has grab?
          Ill test that in a moment.

          update:
          Hide does not release it.

          kshegunovK 1 Reply Last reply
          0
          • mrjjM mrjj

            @Harry123

            hi , just made small test.

            If you new a Widget, let it grab and then delete it, the mouse is restored.
            So seems that delete will release.

            so I guess you hide a window while it has grab?
            Ill test that in a moment.

            update:
            Hide does not release it.

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by kshegunov
            #5

            @Harry123

            I theorize that when the X button is pressed, the window becomes invisible and the releaseMouse is ignored

            Doubtful. You have to match the grabs with releases, possibly you have a codepath somewhere that doesn't go through the release. Also if I recall correctly, you need to call release the exact number of times you call grab.

            @mrjj

            If you new a Widget, let it grab and then delete it, the mouse is restored.

            This is platform specific and ultimately will depend on the window manager. Usually the window manager will release the grab when the receiving native surface handle is destroyed.

            Hide does not release it.

            Nor should it. Grabbing the mouse is quite an exclusive operation.

            Read and abide by the Qt Code of Conduct

            H 1 Reply Last reply
            0
            • kshegunovK kshegunov

              @Harry123

              I theorize that when the X button is pressed, the window becomes invisible and the releaseMouse is ignored

              Doubtful. You have to match the grabs with releases, possibly you have a codepath somewhere that doesn't go through the release. Also if I recall correctly, you need to call release the exact number of times you call grab.

              @mrjj

              If you new a Widget, let it grab and then delete it, the mouse is restored.

              This is platform specific and ultimately will depend on the window manager. Usually the window manager will release the grab when the receiving native surface handle is destroyed.

              Hide does not release it.

              Nor should it. Grabbing the mouse is quite an exclusive operation.

              H Offline
              H Offline
              Harry123
              wrote on last edited by Harry123
              #6

              @mrjj

              It might be that the close button is essential and its handler should release the grab.

              @kshegunov

              I see I was right not to post a bug report, since the case is too vague.

              My understanding is that grab/release in Qt are frowned upon, and my (limited) experience now is that the underlying mouse logic seems solid enough so they are not really required.

              All I can say is that the application, while using Windows API, did release correctly all its grabs. However, under Qt the same application managed to place itself in a situation where the last release did not work and a virtual grab remained in effect. I'm not sure that a simple test program could duplicate this condition.

              kshegunovK 1 Reply Last reply
              0
              • H Harry123

                @mrjj

                It might be that the close button is essential and its handler should release the grab.

                @kshegunov

                I see I was right not to post a bug report, since the case is too vague.

                My understanding is that grab/release in Qt are frowned upon, and my (limited) experience now is that the underlying mouse logic seems solid enough so they are not really required.

                All I can say is that the application, while using Windows API, did release correctly all its grabs. However, under Qt the same application managed to place itself in a situation where the last release did not work and a virtual grab remained in effect. I'm not sure that a simple test program could duplicate this condition.

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by
                #7

                @Harry123 said:

                My understanding is that grab/release in Qt are frowned upon

                Somewhat, albeit sometimes they are needed, hence the mouse grabbing is exposed through the public API.

                the underlying mouse logic seems solid enough so they are not really required

                Yes, most of the time.

                I'm not sure that a simple test program could duplicate this condition.

                Well, the thing is this:
                Even if you post this as a bugreport, you'd want to have some collaboration for someone to pick it up. What I mean is that if you don't provide any means of reproduction (i.e. a test case application) and your description is vague or the bug is very complex/hard to reproduce it may stay in the tracker for a long, long time ... attaching screenshots also might help the developers to triage and ultimately fix the bug.

                Kind regards.

                Read and abide by the Qt Code of Conduct

                H 1 Reply Last reply
                0
                • kshegunovK kshegunov

                  @Harry123 said:

                  My understanding is that grab/release in Qt are frowned upon

                  Somewhat, albeit sometimes they are needed, hence the mouse grabbing is exposed through the public API.

                  the underlying mouse logic seems solid enough so they are not really required

                  Yes, most of the time.

                  I'm not sure that a simple test program could duplicate this condition.

                  Well, the thing is this:
                  Even if you post this as a bugreport, you'd want to have some collaboration for someone to pick it up. What I mean is that if you don't provide any means of reproduction (i.e. a test case application) and your description is vague or the bug is very complex/hard to reproduce it may stay in the tracker for a long, long time ... attaching screenshots also might help the developers to triage and ultimately fix the bug.

                  Kind regards.

                  H Offline
                  H Offline
                  Harry123
                  wrote on last edited by Harry123
                  #8

                  @kshegunov

                  The case I worry about is that of the mouse down and up events. A problem can occur if another window is activated between these two events, especially during a drag operation, meaning that the mouse-up event is received by that other window, so the window to receive the mouse-down event may never fully terminate its handling.

                  This case is rare enough, but potentially destructive to the UI. Do you know if this can happen in Qt when not using manual grab ?

                  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