5

I'm trying to use QAndroidJniObject. As a test I'm just calling 2 Java functions, one returns an int, the other a string.

When returning an int, this code compiles fine:

jint a = QAndroidJniObject::callStaticMethod<jint>("HelloJava", "getInt");

But if I change it to calling a function returning a string, it fails:

jstring b = QAndroidJniObject::callStaticMethod<jstring>("HelloJava", "getString");

It fails with

error: undefined reference to '_jstring* QAndroidJniObject::callStaticMethod<_jstring*>(char const*, char const*)'

Since QAndroidJniObject::callStaticMethod is a template function, how can it be defined for one type but undefined for another?

Edit: Actually, I just tested with jobject, jbyteArray, jbooleanArray, jbyte, jboolean, etc. This is what I found - only the integral number types such as jshort, jint, jlong, jboolean work, while strings, arrays, and objects all give an undefined reference error.

László Papp
  • 51,870
  • 39
  • 111
  • 135
sashoalm
  • 75,001
  • 122
  • 434
  • 781

2 Answers2

5

As you can see in the following table, the integer types are primitive, whereas the rest are object types. Therefore, I suggest that you try using instead:

jstring b = QAndroidJniObject::callStaticObjectMethod<jstring>("HelloJava", "getString")

This is not a bug, but a feature. See this issue tracker entry on the official stance:

QAndroidJniObject/jstring : no reference

Michael
  • 8,362
  • 6
  • 61
  • 88
László Papp
  • 51,870
  • 39
  • 111
  • 135
3

try this:

 QAndroidJniObject jb = QAndroidJniObject::callStaticObjectMethod("HelloJava", "getString", "()Ljava/lang/String;");
 QString b = jb.toString();
mabg
  • 1,894
  • 21
  • 28