diff --git a/apps/opencs/model/doc/documentmanager.cpp b/apps/opencs/model/doc/documentmanager.cpp index cbb255ebb..87fb960c1 100644 --- a/apps/opencs/model/doc/documentmanager.cpp +++ b/apps/opencs/model/doc/documentmanager.cpp @@ -41,6 +41,7 @@ CSMDoc::DocumentManager::DocumentManager (const Files::ConfigurationManager& con CSMDoc::DocumentManager::~DocumentManager() { mLoaderThread.quit(); + mLoader.stop(); mLoader.hasThingsToDo().wakeAll(); mLoaderThread.wait(); diff --git a/apps/opencs/model/doc/loader.cpp b/apps/opencs/model/doc/loader.cpp index 166e6f3db..51b1b5884 100644 --- a/apps/opencs/model/doc/loader.cpp +++ b/apps/opencs/model/doc/loader.cpp @@ -1,6 +1,6 @@ #include "loader.hpp" -#include +#include #include "../tools/reportmodel.hpp" @@ -11,11 +11,12 @@ CSMDoc::Loader::Stage::Stage() : mFile (0), mRecordsLoaded (0), mRecordsLeft (fa CSMDoc::Loader::Loader() + : mShouldStop(false) { - QTimer *timer = new QTimer (this); + mTimer = new QTimer (this); - connect (timer, SIGNAL (timeout()), this, SLOT (load())); - timer->start(); + connect (mTimer, SIGNAL (timeout()), this, SLOT (load())); + mTimer->start(); } QWaitCondition& CSMDoc::Loader::hasThingsToDo() @@ -23,6 +24,11 @@ QWaitCondition& CSMDoc::Loader::hasThingsToDo() return mThingsToDo; } +void CSMDoc::Loader::stop() +{ + mShouldStop = true; +} + void CSMDoc::Loader::load() { if (mDocuments.empty()) @@ -30,6 +36,10 @@ void CSMDoc::Loader::load() mMutex.lock(); mThingsToDo.wait (&mMutex); mMutex.unlock(); + + if (mShouldStop) + mTimer->stop(); + return; } diff --git a/apps/opencs/model/doc/loader.hpp b/apps/opencs/model/doc/loader.hpp index d1ee38f9f..ce5bc5848 100644 --- a/apps/opencs/model/doc/loader.hpp +++ b/apps/opencs/model/doc/loader.hpp @@ -5,6 +5,7 @@ #include #include +#include #include namespace CSMDoc @@ -28,12 +29,17 @@ namespace CSMDoc QWaitCondition mThingsToDo; std::vector > mDocuments; + QTimer* mTimer; + bool mShouldStop; + public: Loader(); QWaitCondition& hasThingsToDo(); + void stop(); + private slots: void load();