Results 1 to 8 of 8

Thread: Are compatible QThreads with Android threads?

  1. #1
    Join Date
    Dec 2015
    Posts
    4
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Android

    Question Are compatible QThreads with Android threads?

    I am new in the forum (altough I have been developing in QT from 5 years ago) so "Hello!" to everybody.

    I am currently developing my first app for Android with QT and QML.


    This is the problem:

    When my app starts, a QThread starts to load a part of the application to don't interrupt the main process.
    When I compile to ubuntu x64, there is no problem, my app launches the QThread and the main thread is not stopped, but, when I start my app in a AVD of Android, the main Thread stops until the operations of the secondary QThread are ended.

    What can I do to separate threads in Android? Are compatible QThread with Android thread? Have I to change the architechture of my app if I want to do it the same in Android that I do in Ubuntu?


    Thanks in advance.

    Regards,

    A.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Are compatible QThreads with Android threads?

    I am pretty sure that both the Android Java Stack as well as the Qt stack use the same operating system threads.
    Qt definitely does and it wouldn't make sense for the Android Java runtime to have their own.

    Have you tried with a minimal example?
    Something like a QTimer in the main thread connected to a slot that makes some log output and a thread which is just a simple loop which does the same?

    Cheers,
    _

  3. #3
    Join Date
    Dec 2015
    Posts
    4
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Android

    Default Re: Are compatible QThreads with Android threads?

    Hi anda_skoa,

    thanks for your reply.

    I have tested that you say with the same result. The main thread waits to the "second thread" (Altought I think that no one new thread is created).

    this is my code:

    @
    int main(int argc, char *argv[])
    {
    //do the operations in a different thread
    //myQThread inherits of QThread
    myQThread*hilo = new myQThread();
    hilo->run();


    Receiver receiver;
    QQmlContext* ctx = engine.rootContext();
    //Introduce receiver as object
    ctx->setContextProperty("receiver", &receiver);

    engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));

    return app.exec();
    }
    @


    I have thought too, that maybe if I use C++ threads instead of QThreads, the app has a different result.

    Some idea ???

    thanks!

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Are compatible QThreads with Android threads?

    You are not starting the new thread, you are executing its run() method in the main thread.

    Cheers,
    _

  5. #5
    Join Date
    Dec 2015
    Posts
    4
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Android

    Default Re: Are compatible QThreads with Android threads?

    Hi again anda_skoa,


    You are right. It has been a mistake from me. I modified that piece of code for count the time in do all the operations in one thread and I forgot it .
    But the code referred to the main question is :

    @
    int main(int argc, char *argv[])
    {
    QGuiApplication app(argc, argv);
    QQmlApplicationEngine engine;

    //do the operations in a different thread
    //MyQThread inherits of QThread
    MyQThread *hilo = new MyQThread ();
    hilo->start();

    Receiver receiver;
    QQmlContext* ctx = engine.rootContext();
    //Introduce receiver as object
    ctx->setContextProperty("receiver", &receiver);

    engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));

    return app.exec();
    }
    @

    Sorry for the inconveniences and thanks for the reply.

    I think that almost nobody develops Android apps with Qt because there is no info enough in QT's web or in forums. I wish this changes because QtQuick is a good tool to do it.

    I am going to try to do it with C++ threads and I will post the result.


    Regards,

    A.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Are compatible QThreads with Android threads?

    So which of the two threads is not running?

    The one used by MyQThread's instance?
    Does it emit the started() signal?

    I am pretty sure that Qt's thread will work, otherwise plenty of Qt internal code would stop working and aside from Qt's automated tests at least some of the application developers would have noticed.

    Cheers,
    _

  7. #7
    Join Date
    Dec 2015
    Posts
    4
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Android

    Default Re: Are compatible QThreads with Android threads?

    Yes , I am talking about MyThread's instance. The signal is emitted.

    About the Qt's threads in Android,
    I supposed it too. But I am not able to do it works in Android.

    I have tried to find some info on the Internet about that topic but I don't have found nothing.

    I keep trying new forms to do it.


    Cheers,

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Are compatible QThreads with Android threads?

    So the thread emits started() but you don't get any output that you put into run()?

    Cheers,
    _

Similar Threads

  1. Replies: 4
    Last Post: 10th July 2014, 15:22
  2. is qtCustomPlot compatible with Android???
    By ale_gia in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 24th May 2014, 10:05
  3. Working properly with threads / QThreads
    By Momergil in forum Qt Programming
    Replies: 3
    Last Post: 6th January 2014, 23:29
  4. How do you make android applications display correctly on android phone?
    By Cyrebo in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 17th August 2013, 07:31
  5. is android app with qt 5.1 just compatible with android 4 ?
    By solook in forum Qt for Embedded and Mobile
    Replies: 5
    Last Post: 14th August 2013, 16:23

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.