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. Why Widget::grabMouse() installs WH_JOURNALRECORD hook on Windows in Qt 4.8.x
Forum Updated to NodeBB v4.3 + New Features

Why Widget::grabMouse() installs WH_JOURNALRECORD hook on Windows in Qt 4.8.x

Scheduled Pinned Locked Moved Solved General and Desktop
qt 4.8.6windows
4 Posts 2 Posters 1.6k 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.
  • J Offline
    J Offline
    JakaBac
    wrote on last edited by JakaBac
    #1

    In Qt 4.8.x Widget::grabMouse() does this on Windows:

    void QWidget::grabMouse()
    {
        if (!qt_nograb()) {
            if (mouseGrb)
                mouseGrb->releaseMouse();
            journalRec = SetWindowsHookEx(WH_JOURNALRECORD, (HOOKPROC)qJournalRecordProc, GetModuleHandle(0), 0);
            Q_ASSERT(testAttribute(Qt::WA_WState_Created));
            SetCapture(effectiveWinId());
            mouseGrb = this;
    #ifndef QT_NO_CURSOR
            mouseGrbCur = new QCursor(mouseGrb->cursor());
    #endif
        }
    }
    

    qJournalRecordProc is defined as:

    // The procedure does nothing, but is required for mousegrabbing to work
    #ifndef Q_WS_WINCE
    LRESULT QT_WIN_CALLBACK qJournalRecordProc(int nCode, WPARAM wParam, LPARAM lParam)
    {
        return CallNextHookEx(journalRec, nCode, wParam, lParam);
    }
    #endif //Q_WS_WINCE
    

    I know that Qt 4.8.x is long out of support and Qt 5 does not do this anymore, but...
    WH_JOURNALRECORD hooks are subjected to various security requirements since Vista or the SetWindowsHookEx call simply fails.

    The thing is, that in some cases it does not fail, but messes up the complete Desktop (until hook is removed by pressing Ctrl+Esc).

    If the hook/unhook calls fail or are removed, applications that call grabMouse still work without any noticeable issues.
    Since this clearly a hack that was obviously needed to make mouse grabbing working, I would very much like to know why it was done in this way and what was the original problem.

    For full implementations of this look here

    Thanks a lot!
    Jaka

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

      Hi
      You will have to ask the devs on the mailing list.
      http://lists.qt-project.org/mailman/listinfo

      We are users here and cant answer why it was done that way :)
      (we would if we could)

      1 Reply Last reply
      3
      • J Offline
        J Offline
        JakaBac
        wrote on last edited by
        #3

        Ok, will do.

        Thanks!

        1 Reply Last reply
        0
        • J Offline
          J Offline
          JakaBac
          wrote on last edited by
          #4

          For sake of completeness here is the answer from Qt developers (in case someone reads this and has the same issue):
          http://lists.qt-project.org/pipermail/development/2018-April/032630.html

          Unfortunately the reason why it was done in that way is still a mystery but it seems that the hook code can be safely removed

          1 Reply Last reply
          2

          • Login

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