Is it possible to create a QGuiApplication in an Android Service?



  • I have a Service that calls a function via JNI where I attempt to create a QGuiApplication but the constructor never finishes. I have loaded the necessary QT libraries and plugins for android similar to how it is done in QtActivity and I don't get any errors, just a dead end.

    Android Service -> java thread -> JNI call -> QThread -> new QGuiApplication...but the constructor never finishes.

    I get a "WARNING: QApplication was not created in the main() thread". Is there a way I can create the QGuiApplication on the main thread from inside a Java thread? Would that even matter?

    Noe: I don't have this problem when using a QCoreApplication.

    Thanks.


  • Moderators

    @jking said:

    Android Service -> java thread -> JNI call -> QThread -> new QGuiApplication...but the constructor never finishes.

    I get a "WARNING: QApplication was not created in the main() thread". Is there a way I can create the QGuiApplication on the main thread from inside a Java thread? Would that even matter?

    Noe: I don't have this problem when using a QCoreApplication.

    Hi, and welcome to the Qt Dev Net!

    QThread is a QObject. You should not create any other QObject before a Q(Core|Gui|)Application. (You note that it worked ok with QCoreApplication, but it's not actually supported.)

    Use a std::thread instead.



  • @JKSH That is helpful information. I had only added the QThread into my flow after not having success creating the QGuiApplication directly in the JNI function. Even without the QThread (and no other created QObjects), the QGuiApplication constructor never returns. I will attempt to debug into QT's code and find where it is getting stalled, but I was hoping someone had an idea of what could be wrong.

    There are no error printouts from QT that I can see in logcat so my current working theory is that I am missing something from the setup of QtActivity in my Service that perhaps the constructor waits on instead of running into an error condition.

    My goal is to have my service initialize several manager classes (which utilize qt signals and slots) and then continue to use the QGuiApplication in my main function when the QtActivity is started.


  • Moderators

    @jking said:

    @JKSH That is helpful information. I had only added the QThread into my flow after not having success creating the QGuiApplication directly in the JNI function. Even without the QThread (and no other created QObjects), the QGuiApplication constructor never returns. I will attempt to debug into QT's code and find where it is getting stalled, but I was hoping someone had an idea of what could be wrong.

    There are no error printouts from QT that I can see in logcat so my current working theory is that I am missing something from the setup of QtActivity in my Service that perhaps the constructor waits on instead of running into an error condition.

    My goal is to have my service initialize several manager classes (which utilize qt signals and slots) and then continue to use the QGuiApplication in my main function when the QtActivity is started.

    Those are interesting symptoms. Sorry I'm not able to help you more with this.

    I suggest you subscribe to the Interest mailing list and ask there -- you can find Qt engineers on that list, who probably know more.

    Good luck!


Log in to reply
 

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