简体   繁体   中英

Binding Android events to Qt application

I have examined the auto-generated QtActivity.java and QtApplication.java , found the skeleton and actual implementations and the simple format they follow. However, from those two sources I could go only as far as the m_delegateObject Object in QtApplication which is the object on which methods are invoked upon receiving events from android.

But I still can't understand where does the delegate object come from. There is public static void setQtActivityDelegate(Object listener) but I have zero idea where this ends up being called. And since there is reflection being used on the delegate, I logically assume it is indeed yet another java object and not a delegate to the actual native application.

My question is how to reach to the actual C++ application and forward a custom event to it, using what mechanism (Qt meta, JNI...?).

Didn't do what you ask exactly but if you receive the notification in java then you can call C++ code from java:

  • In Java you have to declare the native function

package com.test.util; ... private static native void CallCpp(String tag,int prm1,int prm2,int prm3,String prmString);

and in the C++ side register the native fn

  JNINativeMethod methods[] {{"CallCpp","(Ljava/lang/String;IIILjava/lang/String;)V", reinterpret_cast<void> *>(CallCpp)}, }; QAndroidJniObject javaClass("com/tests/util/AndroidEnv"); QAndroidJniEnvironment env; jclass objectClass = env->GetObjectClass(javaClass.object<jobject>()); env->RegisterNatives(objectClass, methods, sizeof(methods) / sizeof(methods[0])); env->DeleteLocalRef(objectClass); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM