How to get an int value using QtAndroid::androidActivity().callObjectMethod?

481 Views Asked by At

I know that using the following method, I could get a string from the Android main activity to Qt/C++ side.

QAndroidJniObject my_string = QtAndroid::androidActivity().callObjectMethod<jstring>("someMethod");
QString  my_qsrting = my_string.toString();

Above is great if someMethod returns a Java String. But what if someMethod returns an int? Following way does not work in Qt? It has compilation errors.

QAndroidJniObject my_int = QtAndroid::androidActivity().callObjectMethod<jint>("someMethod");

How can I collect an int or a jint using QtAndroid::androidActivity().callObjectMethod?

Going through this link, I could not find the answer to my question.

Qt version:
Qt 5.12 commercial version

1

There are 1 best solutions below

1
On BEST ANSWER

You don't use callObjectMethod for methods that return primitives; you use callMethod for that:

jint my_int = QtAndroid::androidActivity().callMethod<jint>("someMethod");