Generate QTouchEvents to simulate touches
-
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?
-
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
-
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?
-
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
-
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?
-
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.
-
Use QWindowSystemInterface::handleTouchEvent to inject touches into the QPA event system. Unlike the sendEvent approach shown above, it is also thread-safe.
-
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? -
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
-
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