Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Callback C++ function from Java: object references mismatch



  • I have QAndroidJniObject (CppClass::jniObject) with MyJavaClass.java class instance. MyJavaClass calls native callback anSignalFromJava()

    static native void anSignalFromJava();
    

    Callback function on C++ side:

    extern "C" {
    JNIEXPORT void JNICALL Java_org_example_MyJavaClass_anSignalFromJava(JNIEnv* env, jobject object) {
    
      qDebug() << "callback object=" << object << "CppClass::jniObject.object()=" << CppClass::jniObject.object(); 
    //output: callback object=0xbea037fc CppClass::jniObject.object()=0x572
    
      Q_ASSERT(object == CppClass::jniObject.object()); //fail
    }
    }
    

    References to same Java object provided by QAndroidJniObject and object parameter of callback function differs, but they should be same


Log in to reply