-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathmytask.cpp
More file actions
36 lines (28 loc) · 807 Bytes
/
mytask.cpp
File metadata and controls
36 lines (28 loc) · 807 Bytes
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
// mytask.cpp
#include "mytask.h"
#include <QDebug>
#include <thread>
#include <chrono>
MyTask::MyTask()
{
qDebug() << "MyTask()";
}
// When the thread pool kicks up
// it's going to hit this run, and it's going to do this time consuming task.
// After it's done, we're going to send the results back to our main thread.
// This runs in the separate thread, and we do not have any control over this thread,
// but Qt does.
// This may just stay in the queue for several ms depending on how busy the server is.
void MyTask::run()
{
// time consumer
qDebug() << "Task started";
int iNumber = 0;
for(int i = 0; i < 100; i++)
{
iNumber += 1;
}
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
qDebug() << "Task done";
emit Result(iNumber);
}