参考:https://blog.csdn.net/li_wen01/article/details/88378914
由于不知道怎么在windows集成开发环境链接phread库,所以使用qt自带的多线程
核心:
1.新建一个继承 < Qthread > 的类
2.在类中重写run函数(这个run函数里的内容就是新线程执行的内容)
3.使用START进行调用
具体:
1.新建一个继承的类
注:别受其他干扰,重要的就是stop和run,
#ifndef THREAD_H
#define THREAD_H
#include<QThread>
#include <QWidget>
class Thread:public QThread
{
public:
Thread();
void setMessage(const QString &message);
void stop();
public:
void run();
private:
QString messageStr;
volatile bool stopped;
};
#endif // THREAD_H
2.在类中重写run函数(这个run函数里的内容就是新线程执行的内容)
注:要把stopped设置成false,即从字面理解就是不停止
#include "thread.h"
#include<QDebug>
Thread::Thread()
{
stopped = false;
}
void Thread::run()
{