質問

Say I have a Java class,

public static String helloWorld() {
    return "hello world!";
}

How, in Qt, do I get what this function returned? The example for notifications has the following:

QAndroidJniObject javaNotification = QAndroidJniObject::fromString(m_notification);
QAndroidJniObject::callStaticMethod<void>("org/qtproject/example/notification/NotificationClient",
                                   "notify",
                                   "(Ljava/lang/String;)V",
                                   javaNotification.object<jstring>());

Should by method descriptor be ()Ljava/lang/String;? What should be in the chevrons after callStaticMethod?

Edit. Fixed and I don't know how. I didn't have the chevrons, and the descriptor was correct.

役に立ちましたか?

解決

QAndroidJniObject string = QAndroidJniObject::callStaticObjectMethod<jstring>("com/your/project/YourClass", "helloWorld");

Is equivalent to:

QAndroidJniObject string = QAndroidJniObject::callStaticObjectMethod("com/your/project/YourClass", "helloWorld", "()Ljava/lang/String;");

For trivial signatures, that is, signatures that takes no arguments and returns one of the know jni types, you can write the short version by supplying the template type.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top