-
Notifications
You must be signed in to change notification settings - Fork 12
/
qanalogthread.cpp
74 lines (60 loc) · 1.27 KB
/
qanalogthread.cpp
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
71
72
73
74
#include "qanalogthread.h"
#include <windows.h>
#include <QApplication>
QAnalogThread* QAnalogThread::pAnalogThread = NULL;
QAnalogThread::QAnalogThread(QObject *parent) :
QThread(parent)
{
bStopSend = false;
nIntervalTime = 2000;
}
QAnalogThread* QAnalogThread::CreateInstance( )
{
if ( NULL == pAnalogThread ) {
pAnalogThread = new QAnalogThread( );
pAnalogThread->moveToThread( pAnalogThread );
pAnalogThread->start( );
}
return pAnalogThread;
}
void QAnalogThread::run( )
{
exec( );
}
void QAnalogThread::AddCmd( QByteArray& byCmd )
{
lstCmds.append( byCmd );
}
void QAnalogThread::ClearCmd( )
{
lstCmds.clear( );
}
void QAnalogThread::SetStopSend( bool bStop )
{
bStopSend = bStop;
}
void QAnalogThread::SetIntervalTime( int nTime )
{
nIntervalTime = nTime;
}
void QAnalogThread::PostEvent( )
{
if ( 0 == lstCmds.count( ) ) {
return;
}
QEvent* pEvent = new QEvent( QEvent::User );
qApp->postEvent( this, pEvent );
}
void QAnalogThread::customEvent(QEvent *e)
{
Q_UNUSED( e )
while ( true ) {
if ( bStopSend ) {
break;
}
foreach ( QByteArray byCmd, lstCmds ) {
emit Command( byCmd );
Sleep( nIntervalTime );
}
}
}