QEventDispatcherWin32 does not handle WM_INPUT messages properly - BUG?
-
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:
-
It is not in production quality.
-
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.
-
-
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.
- Recompile Qt with _WIN32_WINNT=0x501 so that XP (and later) functions are enabled
-
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
-
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.
-
@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]
-
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).aspxWhich 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.
-
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 += consoleDEFINES += _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.
-
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!