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. QEventDispatcherWin32 does not handle WM_INPUT messages properly - BUG?

QEventDispatcherWin32 does not handle WM_INPUT messages properly - BUG?

Scheduled Pinned Locked Moved General and Desktop
12 Posts 4 Posters 11.3k Views
  • 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.
  • U Offline
    U Offline
    Uwe Kindler
    wrote on last edited by
    #3

    Thank you for this hint. Unfortunately the "http://spacenav.sourceforge.net/spnav-win32.html":http://spacenav.sourceforge.net/spnav-win32.html driver is no option for us for two reasons:

    1. It is not in production quality.

    2. It requires "http://sourceforge.net/projects/hidlibrary":http://sourceforge.net/projects/hidlibrary/ which is also in beta state and requires .NET Framework 2.0. We would like to avoid any dependency to .NET Framework.

    I will try to work around the issue by creating a second message pump in a different native Win32 thread that has its own message window and its own windows procedure. But this still does not answer the question why QEventDispatcherWin32 does not handle WM_INPUT messages properly.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dibben
      wrote on last edited by
      #4

      I have been having the same problem trying to get the 3D Connexion mouse working and I think I have discovered where the problem is in QEventDispatcherWin32.

      I am using Qt 4.6.2 with VisualStudio 2005 on Windows XP. The problem I was having was that the WM_INPUT messages were not being received by window/event filter the until some other event such as a mouse or timer event occurred. I could move the 3D mouse and nothing would happen then move the normal mouse and all the 3D mouse events would arrive.

      I traced the problem to
      @MsgWaitForMultipleObjectsEX(nCount, pHandles, INFINITE, QS_ALLINPUT, MWMO_ALERTABLE);@

      In the processEvents function of QEventDispatcherWin32. This was blocking and not waking on WM_INPUT events.

      The windows documentation for this notes that QS_ALLINPUT, which includes QS_INPUT, "does not include QS_RAWINPUT in Windows2000." Therefore I think the problem is that the binary Qt installer is built to work on all windows platforms, so during the compile _WIN32_WINNT is defined to something less that WinXP (0x501) so that raw-input messages are not handled.

      I re-compiled Qt passing -D _WIN32_WINNT=0x501 to configure and now the WM_INPUT messages are being passed to the event filter when the 3D mouse is moved.

      So the options seem to be

      • Recompile Qt with _WIN32_WINNT=0x501 so that XP (and later) functions are enabled
        or
      • Use a timer to unblock the event loop at regular intervals so that the messages get processed. I am not sure yet what effect this will have on the smoothness of the mouse operation.

      I also found that just using the winId() function of the main window for the HWND to use for registering the device also worked fine.

      1 Reply Last reply
      0
      • U Offline
        U Offline
        Uwe Kindler
        wrote on last edited by
        #5

        Hi David,

        hey thank you very much for this solution. We use a self-compiled Qt installation here so it should be no problem to recompile it with _WIN32_WINNT=0×501.

        We worked around the problem by creating a native Win32 DLL (without Qt) that creates an internal win32 message window in its own thread that receives the messages from Space Navigator device. Then we wrote a Qt wrapper for this DLL that translates the messages into Qt events an created a QTDx device.

        But your solution makes it much easier to use Space Navigator from Qt - thank you :O)

        Uwe

        1 Reply Last reply
        0
        • B Offline
          B Offline
          BennM
          wrote on last edited by
          #6

          Hi,

          can anybody of you post an example code which shows how to implement the spacenavigator in qt?

          Thank you very much

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dibben
            wrote on last edited by
            #7

            I wrote an slightly updated version of my comments above and added some sample code of a Qt class to get the data from the mouse on Windows at:

            "http://www.codegardening.com/2011/02/using-3dconnexion-mouse-with-qt.html":http://www.codegardening.com/2011/02/using-3dconnexion-mouse-with-qt.html

            With Qt 4.7.1 it seems to work without having to re-complile the Qt.

            1 Reply Last reply
            0
            • B Offline
              B Offline
              BennM
              wrote on last edited by
              #8

              @David Dibben: Thank you very much for the sample code. I tried to compile it with the qt eclipse integration but it stops during compiling the file "Mouse3DInput.cpp" in line around 345 "pri = NEXTRAWINPUTBLOCK(pri);" complaining that "NEXTRAWINPUTBLOCK was not declared in this scope".

              I added the line in 3DMouse.pro

              @LIBS += -lUser32 -LC:\programs\Microsoft SDKs\Windows\v6.0A\Lib@

              added user32.lib and the paths to the lib und include directories of Microsofts SDKs.

              Is there anything missing?

              [EDIT: code formatting, Volker]

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dibben
                wrote on last edited by
                #9

                NEXTRAWINPUTBLOCK is a windows macro, defined in winuser.h which should be included with windows.h
                See - http://msdn.microsoft.com/en-us/library/ms645593(v=vs.85).aspx

                Which compiler are you using? I am guessing that it is mingw. I don't have experience using g++ on Windows - I compiled the sample using MS VC++ 2008 Express.

                The windows headers should be available with mingw as far as I know, but the windows headers are full of conditional statements so it is possible that something has to be defined for the macros to show up correctly.

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  BennM
                  wrote on last edited by
                  #10

                  Yes I use mingw and did the following changes in your sourcecode:

                  I added this in Mouse3DInput.cpp

                  @#define RAWINPUT_ALIGN(x) (((x) + sizeof(DWORD) - 1) & ~(sizeof(DWORD) - 1))
                  #define NEXTRAWINPUTBLOCK(ptr) ((PRAWINPUT)RAWINPUT_ALIGN((ULONG_PTR)((PBYTE)(ptr) + (ptr)->header.dwSize)))@

                  and this

                  @#include "C:\Qt\2010.05\mingw\include\windows.h"
                  #include "C:\Qt\2010.05\mingw\include\winuser.h"@

                  Then I found a difference between Microsoft's WinUser.h and mingw's winuser.h (see following):
                  @
                  typedef struct tagRAWHID {
                  DWORD dwSizeHid;
                  DWORD dwCount;
                  BYTE bRawData;
                  } RAWHID,*PRAWHID,*LPRAWHID;
                  @
                  I changed it to @bRawData[1]@ like in Microsoft's WinUser.h. I don't know why it works with the range of one, because in the sourcecode you'll find the command
                  @pRawInput->data.hid.bRawData[1] == 0x01@
                  so it must be at least 2, right?

                  Additionally I added
                  @
                  CONFIG += console

                  DEFINES += _WIN32_WINNT="0x0501"
                  DEFINES += _WIN32_WINDOWS="0x0501"

                  INCLUDEPATH += "C:\Qt\2010.05\mingw\include" \

                  LIBS += -luser32 -L"C:\Qt\2010.05\mingw\lib"
                  @

                  to 3DMouse.pro, but I am not shure if I need all of that.

                  After that I was able to compile it. At the moment I am not sure if the translation works correctly, because the data appears too fast in the textboxes, so I will change the program that it saves the data in a textfile.

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    BennM
                    wrote on last edited by
                    #11

                    Hi,

                    I recorded some data which my program (original written by David Dibben) received from the spacenavigator. I made translational movements at first - followed by rotations. There is only noise on the x-axis and no reaction on y- and z-axis. But you can see the translational movements in the last three plots (plots of the rotations). Does anybody has any idea what's going wrong?

                    !http://img6.imagebanana.com/img/ab52tne4/temp.png(plot)!

                    The horizontal axis shows the number of received events - it's not the time!

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      BennM
                      wrote on last edited by
                      #12

                      Hi,

                      I switched to Visual Studio and your code worked out of the box.

                      Thank you for the sample code, David Dibben!

                      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