To run Java code in a Qt Android application, you must use the Qt Android Extras module , which contains additional features for developing on Android.
You can use JNI to call a Java function from C / C ++ or call a C / C ++ function from Java.
Suppose you have a static Java method, for example:
package com.MyApp; public class JavaClass { public static int SomeMethod(int n) { ... } }
First you need to add this to your .pro file:
QT += androidextras
And include the appropriate header file:
#include <QAndroidJniObject>
Then you can call a static java function from your C ++ code, for example:
bool retVal = QAndroidJniObject::callStaticMethod<jint> ("com/MyApp/JavaClass" // class name , "SomeMethod" // method name , "(I)I" // signature , val);
For a more detailed explanation, you can see this .
source share