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. Generate QTouchEvents to simulate touches
Qt 6.11 is out! See what's new in the release blog

Generate QTouchEvents to simulate touches

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 7.9k Views 1 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi and welcome to devnet,

    I can't comment about whether your idea will work or not, however after a quick look at QTouchEvent's documentation, it seems wrong to instantiate your own QTouchDevice. It's the platform plugin that should do that

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • N Offline
      N Offline
      Nex46
      wrote on last edited by
      #3

      Hi, thank you.
      What do you mean by the platform plugin? I assumed that QTouchEvents could be used just like QMouseEvents.

      Any other ideas on how to create an interface for a custom touch device?

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #4

        Qt uses QPA the Q Platform Abstraction concept to implement support for current/new platform. The platform plugins are build based on that. I didn't say the QTouchEvent couldn't be used like that. Just that the QTouchDevice you are creating is probably invalid since it's the QPA part that will create one if a touch device is available

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • N Offline
          N Offline
          Nex46
          wrote on last edited by
          #5

          Ok, I see. The touch device I'm trying to connect does not have a standard interface so it can not be automatically recognized as a touch device.
          The computer communicating with the device receives the coordinates of touchpoints via serial interface and are then sent to my Qt app over dBus.

          Maybe writing a custom plugin using the QPA API is the only way. Anyone who has got any experience or thoughts on this approach?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #6

            If it's already working through D-Bus then you can use the QtDBus module to write a helper class that will send the coordinates through D-Bus. Doing so you can keep your current implementation the same and not fiddle with low-level stuff

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • N Offline
              N Offline
              Nex46
              wrote on last edited by
              #7

              Yes, it's already working with dBus. I'm using the QtDBus module to receive the coordinates in a helper class, but how do I generate the touches in the qml layer. That's what I need help with, and that's why I wrote the test code above to try to generate touch events. Or is it possible to generate an event directly via qbus?

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #8

                Ok, all right, I misunderstood you, sorry.

                For your last question, no it's not. From your test code, I would remove the QTouchDevice, since there are non, giving an "invalid" one could sabotage the event processing.

                Next, I wouldn't use a while loop, you can use a worker object, and give it to a QThread if needed, to implement the event generation.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  agocs
                  wrote on last edited by
                  #9

                  Use QWindowSystemInterface::handleTouchEvent to inject touches into the QPA event system. Unlike the sendEvent approach shown above, it is also thread-safe.

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    Nex46
                    wrote on last edited by
                    #10

                    Hi agocs,

                    I cant seem to find any documentation on QWindowSystemInterface. How do I import the class?
                    I can only find old examples from <2010 and I'm using Qt 5.3. Is QWindowSystemInterface still valid?

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      You'll have to dig in the sources, it's part of the QPA (QPlatform Abstraction) which isn't application API. You can find it under src/gui/kernel

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • N Offline
                        N Offline
                        Nex46
                        wrote on last edited by
                        #12

                        After several attempts to inject QTouchEvents I gave up and went for another solution. By defining a new qml element in C++ that emits a signal (touchActive) when the coordinates are changed and listening to this signal in qml layer (onTouchActive).
                        The drawback is that every multi-touch gesture will have to be interpreted in the C++ class; pinch, zoom etc.
                        For reference see:
                        http://qt-project.org/doc/qt-4.8/qtbinding.html#defining-new-qml-elements

                        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