Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to call JAVA method that returns a String?



  • I would like to call a JAVA method that is in my QtActivity that return a string.

    I've tried these, but all gives me a compilation error:

    jstring value = QtAndroid::androidActivity().callMethod<jstring>("getUser", "()Ljava/lang/String;");
    
    jstring value = QtAndroid::androidActivity().callMethod<jstring>("getUser");
    
    error: undefined reference to '_jstring* QAndroidJniObject::callMethod<_jstring*>(char const*, char const*, ...) const'
    


  • I found it!

        QAndroidJniObject juser = QtAndroid::androidActivity().callObjectMethod("getUser", "()Ljava/lang/String;");
        QString user = juser.toString();
    


  • Thanks for the tip. The problem was callMethod vs callObjectMethod. I think callObjectMethod is for functions that return L types (classes) and the former for primitive types.

    Thanks


Log in to reply