-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathxthread.h
More file actions
70 lines (50 loc) · 1.65 KB
/
xthread.h
File metadata and controls
70 lines (50 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef XTHREAD_H
#define XTHREAD_H
#include <QThread>
#include <QTimer>
#include <functional>
class XThread : public QThread
{
Q_OBJECT
//! 定义回调函数类型
typedef std::function<void(void)> XTHREAD_VOID_FUNC;
typedef std::function<void(int &)> XTHREAD_INT_FUNC;
typedef std::function<void(QString &)> XTHREAD_STRING_FUNC;
public:
XThread(QObject *parent = NULL);
XThread(XTHREAD_VOID_FUNC func, QObject *parent = NULL);
XThread(XTHREAD_INT_FUNC func, QObject *parent = NULL);
XThread(XTHREAD_STRING_FUNC func, QObject *parent = NULL);
~XThread();
//类实例化个数
static int count();
signals:
//线程结束发送运行结果信号
void signalFinishResult(int);
void signalFinishResult(QString);
//线程内部计时器超时发送信号,参数为第几次产生的超时信号
// void signalTimerTimeout(int);
public:
//线程执行回调函数,参数为线程运行结束返回信号类型
void setCallback(XTHREAD_VOID_FUNC func);
void setCallback(XTHREAD_INT_FUNC func);
void setCallback(XTHREAD_STRING_FUNC func);
// int timerInterval() const;
// void setTimerInterval(int msec);
protected:
virtual void run();
//private slots:
// void slotTimerTimeout();
private:
void initBuild();
void runCallbackFunc();
static int m_count;
XTHREAD_VOID_FUNC m_funcVoid;
XTHREAD_INT_FUNC m_funcInt;
XTHREAD_STRING_FUNC m_funcString;
// QTimer *m_timer;
// int m_timerInterval;
// int m_timerTimeoutCounter;
void createTimer();
};
#endif // XTHREAD_H