문제

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