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.
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,
_
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!
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,
_
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.
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,
_
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,
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,
_