How to create QCoreApplication instance in a Qt library with JNI methods for Android java native app?

  • I need develop a Qt library with JNI methods which called by Android java native app. In these JNI methods I need use QBluetooth module to communicate with other bluetooth devices.
    Now I create a shared library project, and then I declare class T inherit from class QThread. In run(), I create a QCoreApplication instance and call exec().
    My codes as below.

    void run() override {
            int argc = 1;
            char *argv[1];
            argv[0] = "name";
            QCoreApplication app(argc, argv);

    In JNI method:

    T *t = NULL;
    JNIEXPORT jboolean JNICALL Jni_init
      (JNIEnv *env, jobject jobj) {
        t = new T();
        return true;

    In .pro file, if like "QT += core", it works fine with a warning: "QApplication was not
    created in main() thread". But if like "QT += core bluetooth", it crashed with an error "libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 24403 (QThread)".

    I'm beginner with Qt, what should I do? Please help me.

  • I solved this problem, after I read this post.( And I found the similar solution which wrote in Chinese.(

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.