-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
79 lines (63 loc) · 3.78 KB
/
main.cpp
File metadata and controls
79 lines (63 loc) · 3.78 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
71
72
73
74
75
76
77
78
79
#include <QCoreApplication>
#include <QTimer>
#include "extentqthread.h"
long baseMSecsSinceEpoch;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
baseMSecsSinceEpoch = QDateTime::currentMSecsSinceEpoch();
qDebug() << QDateTime::currentMSecsSinceEpoch() - baseMSecsSinceEpoch << "Main thread 1" << QThread::currentThreadId();
// === test1
ExtentQThread extQThread1("extQThread1 created from main thread", 10000);
ExtentQObject extQObject10("extQObject10 created from main thread then moved to extQThread1");
extQObject10.moveToThread(&extQThread1);
ExtentQObject extQObject11("extQObject11 created from main thread");
extQThread1.start();
// 1.0 to test signal of extQObject10 which is moved to extQThread1
// and signal of extQObject11 which is not moved
long timeout = 5000;
QTimer::singleShot(timeout, [&extQThread1, &timeout]() {
qDebug() << "\n==" << QDateTime::currentMSecsSinceEpoch() - baseMSecsSinceEpoch << "timeout" << timeout
<< "\n>> To test signal of extQObject10 which is moved to extQThread1 and signal of extQObject11 which is not moved"
<< "\n>> extQThread1.isRunning()" << extQThread1.isRunning();
});
QTimer::singleShot(timeout, &extQObject10, &ExtentQObject::onExtentQObjectFirstSlot);
QTimer::singleShot(timeout, &extQObject11, &ExtentQObject::onExtentQObjectFirstSlot);
#if 0
// 1.1 to test signal of extQThread1 which emit signal to an ExtentQObject created from it before extQThread1::quit
timeout = 2000;
QTimer::singleShot(timeout, [&extQThread1, &timeout]() {
qDebug() << "\n==" << QDateTime::currentMSecsSinceEpoch() - baseMSecsSinceEpoch << "timeout" << timeout
<< "\n>> To test signal of extQThread1 which emit signal to an ExtentQObject created from it BEFORE extQThread1::quit"
<< "\n>> extQThread1.isRunning()" << extQThread1.isRunning();
});
QTimer::singleShot(timeout, &extQThread1, &ExtentQThread::onExtentQThreadFirstSlot);
// 1.2 to call extQThread1::quit
timeout = 3000;
QTimer::singleShot(timeout, [&extQThread1, &timeout]() {
qDebug() << "\n==" << QDateTime::currentMSecsSinceEpoch() - baseMSecsSinceEpoch << "timeout" << timeout
<< "\n>> to call extQThread1::quit"
<< "\n>> extQThread1.isRunning()" << extQThread1.isRunning();
});
QTimer::singleShot(timeout, &extQThread1, &ExtentQThread::quit);
// 1.3 to test signal of extQThread1 which emit signal to an ExtentQObject created from it
// after extQThread1::quit
timeout = 4000;
QTimer::singleShot(timeout, [&extQThread1, &timeout]() {
qDebug() << "\n==" << QDateTime::currentMSecsSinceEpoch() - baseMSecsSinceEpoch << "timeout" << timeout
<< "\n>> To test signal of extQThread1 which emit signal to an ExtentQObject created from it AFTER extQThread1::quit"
<< "\n>> extQThread1.isRunning()" << extQThread1.isRunning();
});
QTimer::singleShot(timeout, &extQThread1, &ExtentQThread::onExtentQThreadFirstSlot);
// 1.0 to test signal of extQObject10 which is moved to extQThread1 after extQThread1::quit
timeout = 5000;
QTimer::singleShot(timeout, [&extQThread1, &timeout]() {
qDebug() << "\n==" << QDateTime::currentMSecsSinceEpoch() - baseMSecsSinceEpoch << "timeout" << timeout
<< "\n>> To test signal of extQObject10 which is moved to extQThread1 AFTER extQThread1::quit"
<< "\n>> extQThread1.isRunning()" << extQThread1.isRunning();
});
QTimer::singleShot(timeout, &extQObject10, &ExtentQObject::onExtentQObjectFirstSlot);
#endif
qDebug() << QDateTime::currentMSecsSinceEpoch() - baseMSecsSinceEpoch << "Main thread 2" << QThread::currentThreadId();
return a.exec();
}