Wednesday 6 July 2011

Joystick test application (Qt + DirectInput8) [Windows]

  This application is provided to test joystick output using DirectInput8. It reports the axis positions, as well as the buttons' state.

  Download link:
       application archive (zip): Public_QtJoystick - version 0.2b [Win32/i386] - 4.53 MiB
       source code (zip): Source_QtJoystick - version 0.2b - 292 KiB

    It will be later used in my OGL6 tank game and robot simulation (which is based on the game's engine). Any suggestions, questions and comments are welcome. It is distributed under the LGPL or MIT license on your choice.

    It is written with Qt SDK 1.1 & QtCreator 2.1. Source code is available for download and use under the LGPLv2 or MIT license.

  Usage:
1) Download Public_QtJoystick .zip archive
2) Unpack it with windows zip unpacker or any archive tool (like 7-zip) to any directory
3) Plug in the joystick (if it isn't plugged yet)
4) Run QtJoystick.exe

11 comments:

  1. hi your program is great, when i run it everything is ok, but when i open the project with Qt run it, it gives me a lot of errors from dinput.h file. Im using linux. Thanks for your answer. Your demo is really great XD.

    ReplyDelete
    Replies
    1. Hello, Luis. Unfortunately, this program shall compile only under Windows, because it makes use of Windows-dependent component: DirectX, for which there isn't cross-platform header file dinput.h.

      Your program could start in Linux inside Windows emulator (Linux can not execute *.exe Win32/PE files natively).

      To solve your problem, you shall probably try to use SFML library (http://www.sfml-dev.org/). Just download and run SFML library for Linux 32/64 bits and follow documentation. Joystick usage is very simple and straightforward with that library.
      Look at C++ class sf::Input (http://www.sfml-dev.org/documentation/1.6/classsf_1_1Input.php).

      I will write small cross-platform demo for Qt+SFML to support Joystick under Linux/Windows within few days.

      Delete
  2. Hi. I tried compiling your code, but I get the following errors:

    line: for (int r = 0; r < std::min(tblAxis.rows(),8); r++)

    ..\QtJoystick\mainwindow.cpp(48) : error C2589: '(' : illegal token on right side of '::'
    ..\QtJoystick\mainwindow.cpp(48) : error C2059: syntax error : '::'
    ..\QtJoystick\mainwindow.cpp(48) : error C2143: syntax error : missing ';' before ')'
    ..\QtJoystick\mainwindow.cpp(48) : error C2143: syntax error : missing ';' before ')'
    ..\QtJoystick\mainwindow.cpp(49) : error C2143: syntax error : missing ';' before '{'

    ReplyDelete
  3. Your code example is excellent and ran straight away. Also, it was very easy to integrate into my test application. Many thanks for sharing!

    ReplyDelete
  4. Hi, the links for the source and demo are no longer valid. Is it possible to have them updated ?

    ReplyDelete
    Replies
    1. they are valid buddy....check them again...they worked well for me

      Delete
    2. The source and binary location were broken for a while because of updated upload scripts on the hosting. Probably worth uploading all of the code base from private hosting to github, so everyone can improve and fork them easily. I will do that in few days :)

      Delete
  5. Hi ,
    im trying to use your awesome code in my application, but i meet some problems with f_haveJoystick = input.initDInput(this->winId());
    invalid conversion from 'WId {aka unsigned int}' to 'HWND' [-fpermissive] f_haveJoystick = input.initDInput(this->effectiveWinId());
    ^

    ReplyDelete
    Replies
    1. Hi,
      which compiler and OS are you using? This seems like gcc specific error message. This is not a real mistake here, as HWND is a windows Handle and should be 32 bit integer normally. You can cast type safely there.

      f_haveJoystick = input.initDInput((HWND)this->effectiveWinId());

      The code was developed originally with visual C++ which is less C++ standard compatible as gcc. GCC is right in this case. I will update the code.

      Does above mentioned type cast work for you?

      Delete
  6. Hello, thank you for sharing the program and it is great! but when I run it on QT5, there will be some problem, for example ,some function on XInput could not be used. I want to know how to make it run successfully on QT5?

    ReplyDelete
  7. Hi
    The download link no longer works. Is it possible to get the source code somehow?

    ReplyDelete

Locations of visitors to this page