You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
959 B
C++
46 lines
959 B
C++
#ifndef _QMYTHREAD_H_
|
|
#define _QMYTHREAD_H_
|
|
|
|
#include <QThread>
|
|
#include <iostream>
|
|
#include <stdio.h>
|
|
#include <QMutex>
|
|
#include <functional>
|
|
|
|
typedef std::function<void()> TaskFunc;
|
|
class QMyThread : public QThread
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
QMyThread(QObject *parent = 0, quint64 m_sleeptime=10);
|
|
~QMyThread();
|
|
|
|
bool loadfunc(TaskFunc func)/*模板函数 不知道怎么使用*/
|
|
{
|
|
_actionFunc = func;
|
|
return true;
|
|
}
|
|
|
|
void InitStopFlag(){ stopped = false; };
|
|
void stop();
|
|
void setUser(bool m_userCtrol = false){ this->userCtrol = m_userCtrol; };
|
|
bool WaitForSingle(quint8 m_sleep = 10);
|
|
bool getStopFlag();
|
|
void setSleepTime(quint64 sleeptime = 10){ m_sleeptime = sleeptime; };
|
|
private:
|
|
QMutex m_lock;
|
|
bool userCtrol;
|
|
volatile bool stopped;
|
|
QString messageStr;
|
|
TaskFunc _actionFunc;
|
|
bool m_stopsleep;
|
|
quint64 m_sleeptime;
|
|
private slots:
|
|
void WaitSingleIn(bool m_signal);
|
|
protected:
|
|
void run();
|
|
void runTsk();
|
|
};
|
|
#endif // QMYTHREAD_H
|