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 = ...
!