QThread output problem
-
Hello I have problem with my simple QThread application. The output is really strange can anybody help me?
Here is my code.main.cpp
@#include <QCoreApplication>
#include "mythread.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);MyThread mThread1; mThread1.name = "mThread1"; MyThread mThread2; mThread2.name = "mThread2"; MyThread mThread3; mThread3.name = "mThread3"; mThread1.start(); mThread2.start(); mThread3.start(); return a.exec();
}@
mythread.cpp
@#include "mythread.h"
#include <QtCore>
#include <QDebug>MyThread::MyThread()
{
}
void MyThread::run()
{qDebug() << this->name << "Running!"; for(int i=0; i<1000; i++){ qDebug() << this->name << i; }
}@
mythread.h
@#ifndef MYTHREAD_H
#define MYTHREAD_H
#include <QtCore>class MyThread : public QThread
{
public:
MyThread();
void run();
QString name;
};#endif // MYTHREAD_H@
The output is this
https://www.dropbox.com/s/cjnxb16qih102ph/cmd.png -
looks ok to me. Of course if they all write to the console simultaneously the output might be like in the screenshot you posted.
A mixup of "mThread1 843" and "mThread3 859" would result in something like you have :
"mThread3"m" 8Threa59ad1" 843 " or any other combination possible.