PDA

View Full Version : Can't filter native events on Android



justin123
23rd December 2014, 14:26
Is it possible to use the QAbstractNativeEventFilter on Android yet? I've tried subclassing it and reimplementing the nativeEventFilter function, but it is never called. The same code does work on Windows though. I need this functionality to pass events on to a 3rd-party input library for a game engine that I'm working on. Any input is much appreciated.


Thanks!

anda_skoa
23rd December 2014, 15:19
All the UI events on Android are Java interface method calls (callbacks) and get translated in Qt/C++ events inside the Qt platform adapter plugin.
Which then sends them directly to the window in questions.

The event dispatcher only sees native Unix events, e.g. for sockets or timers.

Just to clarify: you need the native events, i.e. the Java event objects because the engine is written in Java?

Cheers,
_

justin123
23rd December 2014, 21:01
All the UI events on Android are Java interface method calls (callbacks) and get translated in Qt/C++ events inside the Qt platform adapter plugin.
Which then sends them directly to the window in questions.

The event dispatcher only sees native Unix events, e.g. for sockets or timers.

Just to clarify: you need the native events, i.e. the Java event objects because the engine is written in Java?

Cheers,
_

The native events is what I need (touch and motion events) from the java side of things. The engine is being written in C++ though, so I'm not sure how to set the callback functions properly, or how to even access them from Qt.

Here is how it is achieved using native android without Qt:
https://github.com/jkuhlmann/gainput/blob/master/samples/basic/basicsample_android.cpp

I must admit that I'm relatively new to programming Qt on Android and Android development in general, but so far this has been the only snag.

anda_skoa
24th December 2014, 11:00
If you can transform from Java objects to C++, why not convert the Qt event objects to the target C++ objects instead?

I.e. the Qt platform plugin transforms the Java events to Qt events and passes them to the window. You then convert the Qt event to engine event and pass that to the engine.

Cheers,
_

justin123
24th December 2014, 18:06
If you can transform from Java objects to C++, why not convert the Qt event objects to the target C++ objects instead?

I.e. the Qt platform plugin transforms the Java events to Qt events and passes them to the window. You then convert the Qt event to engine event and pass that to the engine.

Cheers,
_

Well, I got it to work by just modifying the input library to use Qt events directly since the Qt event provides the same information.