##// END OF EJS Templates
Ajout de la méthode wait pour éviter de détruire un thread en cours...
perrinel -
r22:ac81b58d0bc3
parent child
Show More
@@ -1,47 +1,45
1 1 #include "DataSource/DataSourceController.h"
2 2
3 3 #include <QMutex>
4 4 #include <QThread>
5 5
6 6 Q_LOGGING_CATEGORY(LOG_DataSourceController, "dataSourceController")
7 7
8 8 class DataSourceController::DataSourceControllerPrivate {
9 9 public:
10 10 DataSourceControllerPrivate() {}
11 11
12
13 12 QMutex m_WorkingMutex;
14 13 };
15 14
16 15 DataSourceController::DataSourceController(QObject *parent)
17 16 : impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()}
18 17 {
19 qCInfo(LOG_DataSourceController()) << tr("Construction du DataSourceController");
18 qCDebug(LOG_DataSourceController()) << tr("Construction du DataSourceController")
19 << QThread::currentThread();
20 20 }
21 21
22 22 DataSourceController::~DataSourceController()
23 23 {
24 // delete impl;
24 qCDebug(LOG_DataSourceController()) << tr("Desctruction du DataSourceController")
25 << QThread::currentThread();
25 26 this->waitForFinish();
26 27 }
27 28
28 29 void DataSourceController::initialize()
29 30 {
30 qCInfo(LOG_DataSourceController()) << tr("initialize du DataSourceController");
31 qCDebug(LOG_DataSourceController()) << tr("initialize du DataSourceController")
32 << QThread::currentThread();
31 33 impl->m_WorkingMutex.lock();
32 qCInfo(LOG_DataSourceController()) << tr("initialize du DataSourceController END");
34 qCDebug(LOG_DataSourceController()) << tr("initialize du DataSourceController END");
33 35 }
34 36
35 37 void DataSourceController::finalize()
36 38 {
37 qCInfo(LOG_DataSourceController()) << tr("finalize du DataSourceController");
38 39 impl->m_WorkingMutex.unlock();
39 qCInfo(LOG_DataSourceController()) << tr("finalize du DataSourceController END");
40 40 }
41 41
42 42 void DataSourceController::waitForFinish()
43 43 {
44 qCInfo(LOG_DataSourceController()) << tr("waitForFinish du DataSourceController");
45 44 QMutexLocker locker(&impl->m_WorkingMutex);
46 qCInfo(LOG_DataSourceController()) << tr("waitForFinish du DataSourceController END");
47 45 }
@@ -1,40 +1,46
1 1 #include "SqpApplication.h"
2 2
3 3 #include <DataSource/DataSourceController.h>
4 4 #include <QThread>
5 5
6 6 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
7 7
8 8 class SqpApplication::SqpApplicationPrivate {
9 9 public:
10 10 SqpApplicationPrivate() {}
11 ~SqpApplicationPrivate()
12 {
13 qCInfo(LOG_SqpApplication()) << tr("Desctruction du SqpApplicationPrivate");
14 ;
15 m_DataSourceControllerThread.quit();
16 m_DataSourceControllerThread.wait();
17 }
11 18
12 19 std::unique_ptr<DataSourceController> m_DataSourceController;
13 20 QThread m_DataSourceControllerThread;
14 21 };
15 22
16 23
17 24 SqpApplication::SqpApplication(int &argc, char **argv)
18 25 : QApplication(argc, argv), impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
19 26 {
20 27 qCInfo(LOG_SqpApplication()) << tr("Construction du SqpApplication");
21 28
22 29 impl->m_DataSourceController = std::make_unique<DataSourceController>();
23 30 impl->m_DataSourceController->moveToThread(&impl->m_DataSourceControllerThread);
24 31
25 32 connect(&impl->m_DataSourceControllerThread, &QThread::started,
26 33 impl->m_DataSourceController.get(), &DataSourceController::initialize);
27 34 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
28 35 impl->m_DataSourceController.get(), &DataSourceController::finalize);
29 36
30 37 impl->m_DataSourceControllerThread.start();
31 38 }
32 39
33 40 SqpApplication::~SqpApplication()
34 41 {
35 impl->m_DataSourceControllerThread.quit();
36 42 }
37 43
38 44 void SqpApplication::initialize()
39 45 {
40 46 }
General Comments 4
Under Review
author

Auto status change to "Under Review"

Approved
author

Status change > Approved

You need to be logged in to leave comments. Login now