How to mix C++ Qt objects and Qt Jambi objects
- by Dan
Hi,
I'm 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 it. I'm basically trying to acieve two things:
Pass a QObject from C++ to Java using JNI
Pass a Qt Jambi QObject from Java to C++
It looks like I can pass the pointer directly and then wrap it in QNativePointer on the Java side, but I can't figure out how to turn a QNativePointer back into the original object, wrapped by Qt Jambi.
Eg: I can pass a QWidget* as a long to Java and then create a QNativePointer in Java, but how can I then construct a QWidget out of this? QJambiObject and QObject dont 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 = ...
Thanks!