This repository has been archived by the owner on Jan 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mythread.h
112 lines (72 loc) · 1.75 KB
/
mythread.h
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <QObject>
#include <QDebug>
#include <QThread>
#include<qtimer>
#include"QtCore"
#include"input_file.h"
#include"water_reading.h"
#include"struttura_dati.h"
#include"qmutex.h"
class Worker : public QObject
{
Q_OBJECT
public slots:
void doWork(const QString ¶meter) {
QString result;
/* ... here is the expensive or blocking operation ... */
emit resultReady(result);
}
signals:
void resultReady(const QString &result);
};
class Controller : public QObject
{
Q_OBJECT
QThread workerThread;
public:
Controller() {
Worker *worker = new Worker;
worker->moveToThread(&workerThread);
connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater);
connect(this, &Controller::operate, worker, &Worker::doWork);
connect(worker, &Worker::resultReady, this, &Controller::handleResults);
workerThread.start();
}
~Controller() {
workerThread.quit();
workerThread.wait();
}
public slots:
void handleResults(const QString &);
signals:
void operate(const QString &);
};
/*
class Worker : public QObject
{
Q_OBJECT
private slots:
void onTimeout()
{
QMutex mutex;
mutex.lock();
mutex.unlock();
qDebug()<<"Worker:: "<<QThread::currentThreadId();
//input_file::read_file(Struttura_dati::Wreading,Struttura_dati::FilePath.toStdString());
}
};
class Thread : public QThread
{
Q_OBJECT
private:
void run()
{
qDebug()<<"thread n*: "<<currentThreadId();
Worker worker;
QTimer timer;
connect(&timer, SIGNAL(timeout()), &worker, SLOT(onTimeout()));
timer.start(1000);
this->quit();
exec();
}
};*/