简体   繁体   English

将Android事件绑定到Qt应用程序

[英]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. 我检查了自动生成的QtActivity.javaQtApplication.java ,发现了框架和实际实现以及它们遵循的简单格式。 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. 然而,来自这两个来源,我可以只去尽可能的m_delegateObject的对象QtApplication这是其方法是在从机器人接收事件调用的对象。

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. public static void setQtActivityDelegate(Object listener)但我不知道最终会在哪里调用。 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. 并且由于在委托上使用了反射,因此我从逻辑上假设它确实是另一个java对象,而不是实际本机应用程序的委托。

My question is how to reach to the actual C++ application and forward a custom event to it, using what mechanism (Qt meta, JNI...?). 我的问题是如何使用哪种机制(Qt meta,JNI ...?)到达实际的C ++应用程序并将自定义事件转发给它。

Didn't do what you ask exactly but if you receive the notification in java then you can call C++ code from java: 没有完全按照您的要求进行操作,但是如果您收到了Java通知,则可以从Java调用C ++代码:

  • In Java you have to declare the native function 在Java中,您必须声明本机函数

package com.test.util; 包com.test.util; ... private static native void CallCpp(String tag,int prm1,int prm2,int prm3,String prmString); ...私有静态本机无效CallCpp(String tag,int prm1,int prm2,int prm3,String prmString);

and in the C++ side register the native fn 并在C ++端注册本地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); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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