[Solved] Threads not running concurrently
-
Hi,
I'm watching "this":http://www.youtube.com/watch?v=JaGqGhRW5Ks video tutorial.
I created three threads as same as mentioned there.
@#include <QtCore/QCoreApplication>
#include "mythread.h"int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);Mythread mthread1; mthread1.setObjectName("mthread1"); Mythread mthread2; mthread2.setObjectName("mthread2"); Mythread mthread3; mthread3.setObjectName("mthread3"); mthread1.run(); mthread2.run(); mthread3.run(); return a.exec();
}@
And my run() method like below.
@void Mythread::run()
{qDebug()<< this->objectName() << "Running"; for(int i =0; i<100000;i++) { qDebug()<< this->objectName() << i; }
}@
When I compile and run the app threads not running concurrently. They run one after the other.
But In tutorial video they are running concurrently.What is the problem?
Thanks in advance.
-
Sorry my friends. I used @mthread1.run();@ instead of @mthread1.start();@
-
Hi,
The use of QThread is wrong in that video!! Skip to part 5 where he explains why! -
@ Jeroentje,
Ohh. really?
Thank you very much for the information.. I'll move to part 5.. -
Better read this part:
"Your text to link here...":http://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/The QThread class is very low level way of programming multithreaded applications! You might want to look into QtConcurrent classes! There the threads are run in the background and makes it much more easy to run multithreads safely!
"QtConcurrent":http://qt-project.org/doc/qt-5.0/qtconcurrent/qtconcurrent-index.html -
Thank you Jeroentje. I'll read those.
Thanks again.
-
Hi,
Maya's blog and Qt Concurrent aren't the whole story. For example, Qt Concurrent cannot be used for threads that last for a long time, or for inter-thread communication.
There are a few different ways to do multithreading in Qt. This page compares all of them, and helps users choose an appropriate method: http://qt-project.org/doc/qt-5/threads-technologies.html
-
Thank you JKSH.
I still haven't got time to read it. But I'll read it ASAP.