Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to create QCoreApplication instance in a Qt library with JNI methods for Android java native app?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved Mobile and Embedded
2 Posts 1 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rel1ve
    wrote on last edited by
    #1

    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);
    
            app.exec();
        }
    

    In JNI method:

    T *t = NULL;
    
    JNIEXPORT jboolean JNICALL Jni_init
      (JNIEnv *env, jobject jobj) {
        t = new T();
        t->start();
        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.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rel1ve
      wrote on last edited by
      #2

      I solved this problem, after I read this post.(https://microscopictopic.wordpress.com/2015/01/15/using-qt-instead-of-the-android-ndk/). And I found the similar solution which wrote in Chinese.(http://blog.csdn.net/promotergmy/article/details/70941649)

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved