Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Polling for SDL events in a custom QObject-derived C++ class?

    QML and Qt Quick
    2
    2
    1967
    Loading More Posts
    • 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.
    • K
      katanaswordfish last edited by

      I'm in the process of writing a QML/QtQuick application, and my goal is to be able to control this app with a variety of input devices; including some that don't seem to be officially supported by Qt like gamepad/joystick input.

      It seems that the best way to go about this might be to create a new QObject-derived class in C++ that wraps "SDL's Event System":http://www.libsdl.org/release/SDL-1.2.15/docs/html/sdlevent.html, independently checking for gamepad/joystick events and emitting signals to be used by my other QObject/QML instances.

      I'm pretty new to Qt/QML still, so I'm not sure of the right way to go about this though. Every frame/update I need my QObject class to call SDL_PollEvent() in a loop (in order to retrieve each event from the internal event queue). After I poll events, I need to process the event to determine what type of event it was. After that, my plan is to emit a Qt signal specific to the event that was just processed (for example: onJoyPadLeft() signal or onJoyPadButton5() signal).

      I think I could probably make a new thread that constantly polls/processes SDL events. However, I don't want to do that if there is a better way that's built into QObjects. Is there some kind of QObject function that's called each frame/update that I can use/overwrite for the sake of polling/processing SDL events? Or should I make a new thread that runs its own event-handling loop?

      1 Reply Last reply Reply Quote 0
      • P
        pritamghanghas last edited by

        If the API that you are using for polling events is blocking, then a thread is the only option. Otherwise you can install a even filter at either the QApplication or your top level widget and do you work whenever a paint event comes.

        In case of QML, I dont remember the exact details but scenegraph renders emit frame start and frameend signals. A simple search on google should give you the exact api.

        Just be aware if the poll method will take a long time thread approach will be better

        1 Reply Last reply Reply Quote 0
        • First post
          Last post