How to mix Qt Qt objects and Qt Jambi objects

I am trying to combine some existing Qt code written in C ++ with some code written in Java using Qt Jambi, but I'm not quite sure how to do this. I mainly try to do two things:

  • Pass a QObject from C ++ to Java using JNI
  • Pass Qt Jambi QObject from Java to C ++

It seems like I can pass the pointer directly and then wrap it in a QNativePointer from the Java side, but I cannot figure out how to turn the QNativePointer back into the original object wrapped by Qt Jambi.

For example: I can pass QWidget * as a long path to Java and then create a QNativePointer in Java, but how can I then build a QWidget from this? QJambiObject and QObject do not seem to have a setNativePointer method, and I'm not sure how to convert it.

In C ++:

QWidget* widget = ...
jclass cls = env->FindClass("Test");
jmethodID mid = env->GetStaticMethodID(cls, "test", "(I)V");
env->CallStaticVoidMethod(cls, mid, int(widget));

In Java:

public class Test {
    public static void test (int ptr) {
        QNativePointer pointer = new QNativePointer(QNativePointer.Type.Int);
        pointer.setIntValue(ptr);

        QWidget widget = ...

!

+3
2

, , : http://labs.trolltech.com/blogs/2007/08/24/extremely-interesting-jambi-trick-x-instantiating-java-widgets-from-c/

:

qtjambi_from_QWidget() Java-, ++ Java , . java , Java-, Qt Jambi. ++ , . , qtjambi_core.h , ++ JNI, , JNI-.

+2

, , . , - ++ QWidget Java QWidget. , Java ++ , .

, , , , , QtJambi QWidget ++ QWidget.

- ++ QWidget, QtJambi QWidget QtJambi. , , , .

+2

Source: https://habr.com/ru/post/1725533/


All Articles