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. Is it possible to create a QGuiApplication in an Android Service?

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

Scheduled Pinned Locked Moved Mobile and Embedded
androidqguiapplication
4 Posts 2 Posters 2.4k 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.
  • J Offline
    J Offline
    jking
    wrote on 8 Apr 2015, 21:27 last edited by
    #1

    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.

    J 1 Reply Last reply 8 Apr 2015, 23:51
    0
    • J jking
      8 Apr 2015, 21:27

      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.

      J Offline
      J Offline
      JKSH
      Moderators
      wrote on 8 Apr 2015, 23:51 last edited by JKSH 4 Aug 2015, 23:51
      #2

      @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.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      J 1 Reply Last reply 9 Apr 2015, 13:01
      0
      • J JKSH
        8 Apr 2015, 23:51

        @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.

        J Offline
        J Offline
        jking
        wrote on 9 Apr 2015, 13:01 last edited by
        #3

        @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.

        J 1 Reply Last reply 9 Apr 2015, 13:29
        0
        • J jking
          9 Apr 2015, 13:01

          @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.

          J Offline
          J Offline
          JKSH
          Moderators
          wrote on 9 Apr 2015, 13:29 last edited by
          #4

          @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!

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0

          1/4

          8 Apr 2015, 21:27

          • Login

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