error C2668: “QThread::start”: 对重载函数的调用不明确
#include <iostream>
#include <QThread>
#include <QString>
class MyThread : public QThread
{
Q_OBJECT
public:
MyThread(QString name = "") {
stopped = false;
this->name = name;
}
void run() {
while (!stopped) {
std::cout << "In " << name.toStdString() << "'s run()." << std::endl;
QThread::msleep(400);
}
}
void stop() {
stopped = true;
}
private:
volatile bool stopped;
QString name;
};
int main()
{
MyThread thread;
MyThread thread1("Thread1");
MyThread thread2("Thread2");
//
thread.start();
thread1.start();
thread2.start();
return 0;
}
#include <QCoreApplication>
#include <QThread>
#include "MyThread.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
MyThread thread;
thread.start();
return a.exec();
}
#ifndef MYTHREAD_H
#define MYTHREAD_H
#include <QThread>
class MyThread:public QThread
{
protected:
void run();
};
#endif // MYTHREAD_H
#include "MyThread.h"
#include <stdio.h>
void MyThread::run()
{
while(1){
printf("A");
}
}