Running java file in qt

I am trying to execute a java file inside qt, here is my java file code:

import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.content.Context; public class Main extends AppWidgetProvider { @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { // TODO Auto-generated method stub super.onUpdate(context, appWidgetManager, appWidgetIds); } } 

The question is how this java file can be called, I got confused and don’t know how to call the onUpdate function, any ideas?

+5
source share
1 answer

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 .

+5
source

Source: https://habr.com/ru/post/981903/


All Articles