Merge remote-tracking branch 'aesylwinn/QTimerFix'

This commit is contained in:
Marc Zinnschlag 2016-06-11 11:26:14 +02:00
commit 148f2c9539
3 changed files with 21 additions and 4 deletions

View file

@ -41,6 +41,7 @@ CSMDoc::DocumentManager::DocumentManager (const Files::ConfigurationManager& con
CSMDoc::DocumentManager::~DocumentManager() CSMDoc::DocumentManager::~DocumentManager()
{ {
mLoaderThread.quit(); mLoaderThread.quit();
mLoader.stop();
mLoader.hasThingsToDo().wakeAll(); mLoader.hasThingsToDo().wakeAll();
mLoaderThread.wait(); mLoaderThread.wait();

View file

@ -1,6 +1,6 @@
#include "loader.hpp" #include "loader.hpp"
#include <QTimer> #include <iostream>
#include "../tools/reportmodel.hpp" #include "../tools/reportmodel.hpp"
@ -11,11 +11,12 @@ CSMDoc::Loader::Stage::Stage() : mFile (0), mRecordsLoaded (0), mRecordsLeft (fa
CSMDoc::Loader::Loader() CSMDoc::Loader::Loader()
: mShouldStop(false)
{ {
QTimer *timer = new QTimer (this); mTimer = new QTimer (this);
connect (timer, SIGNAL (timeout()), this, SLOT (load())); connect (mTimer, SIGNAL (timeout()), this, SLOT (load()));
timer->start(); mTimer->start();
} }
QWaitCondition& CSMDoc::Loader::hasThingsToDo() QWaitCondition& CSMDoc::Loader::hasThingsToDo()
@ -23,6 +24,11 @@ QWaitCondition& CSMDoc::Loader::hasThingsToDo()
return mThingsToDo; return mThingsToDo;
} }
void CSMDoc::Loader::stop()
{
mShouldStop = true;
}
void CSMDoc::Loader::load() void CSMDoc::Loader::load()
{ {
if (mDocuments.empty()) if (mDocuments.empty())
@ -30,6 +36,10 @@ void CSMDoc::Loader::load()
mMutex.lock(); mMutex.lock();
mThingsToDo.wait (&mMutex); mThingsToDo.wait (&mMutex);
mMutex.unlock(); mMutex.unlock();
if (mShouldStop)
mTimer->stop();
return; return;
} }

View file

@ -5,6 +5,7 @@
#include <QObject> #include <QObject>
#include <QMutex> #include <QMutex>
#include <QTimer>
#include <QWaitCondition> #include <QWaitCondition>
namespace CSMDoc namespace CSMDoc
@ -28,12 +29,17 @@ namespace CSMDoc
QWaitCondition mThingsToDo; QWaitCondition mThingsToDo;
std::vector<std::pair<Document *, Stage> > mDocuments; std::vector<std::pair<Document *, Stage> > mDocuments;
QTimer* mTimer;
bool mShouldStop;
public: public:
Loader(); Loader();
QWaitCondition& hasThingsToDo(); QWaitCondition& hasThingsToDo();
void stop();
private slots: private slots:
void load(); void load();