第一次上传
This commit is contained in:
36
Threads/SubThread.cpp
Normal file
36
Threads/SubThread.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "SubThread.h"
|
||||
|
||||
SubThread::SubThread()
|
||||
{
|
||||
isPause = false;
|
||||
isLoop = true;
|
||||
}
|
||||
void SubThread::ReStart(){
|
||||
isPause = false;
|
||||
}
|
||||
void SubThread::PauseThread()
|
||||
{
|
||||
isPause = true;
|
||||
}
|
||||
void SubThread::KillThread()
|
||||
{
|
||||
isLoop = false;
|
||||
wait();
|
||||
thread()->quit();
|
||||
}
|
||||
|
||||
void SubThread::executeThreadLogic()
|
||||
{
|
||||
// 在这里实现线程的逻辑
|
||||
|
||||
while (isLoop)
|
||||
{
|
||||
QThread::msleep(CONFIG_EN_SUB_THREAD_TIME);//这个是子线程的基础时间,意在多长时间循环一次,单位毫秒
|
||||
if(isPause) continue;
|
||||
|
||||
}
|
||||
}
|
||||
void SubThread::run()
|
||||
{
|
||||
executeThreadLogic();
|
||||
}
|
||||
23
Threads/SubThread.h
Normal file
23
Threads/SubThread.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef SUBTHREAD_H
|
||||
#define SUBTHREAD_H
|
||||
|
||||
#include <QThread>
|
||||
#include <GlobalDefinitions/Variable.h>
|
||||
class SubThread : public QThread
|
||||
{
|
||||
|
||||
public:
|
||||
SubThread();
|
||||
void ReStart();
|
||||
void PauseThread();
|
||||
void KillThread();
|
||||
private:
|
||||
void executeThreadLogic(); // 执行线程逻辑的函数
|
||||
protected:
|
||||
void run() override; // 重写run函数不再需要
|
||||
private:
|
||||
bool isLoop;
|
||||
bool isPause;
|
||||
};
|
||||
|
||||
#endif // SUBTHREAD_H
|
||||
Reference in New Issue
Block a user