mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 18:49:58 +00:00
Fix QTimer not being stopped in right thread
This commit is contained in:
parent
3dce406829
commit
f6c3b44cfb
3 changed files with 21 additions and 4 deletions
|
@ -41,6 +41,7 @@ CSMDoc::DocumentManager::DocumentManager (const Files::ConfigurationManager& con
|
|||
CSMDoc::DocumentManager::~DocumentManager()
|
||||
{
|
||||
mLoaderThread.quit();
|
||||
mLoader.stop();
|
||||
mLoader.hasThingsToDo().wakeAll();
|
||||
mLoaderThread.wait();
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "loader.hpp"
|
||||
|
||||
#include <QTimer>
|
||||
#include <iostream>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QMutex>
|
||||
#include <QTimer>
|
||||
#include <QWaitCondition>
|
||||
|
||||
namespace CSMDoc
|
||||
|
@ -28,12 +29,17 @@ namespace CSMDoc
|
|||
QWaitCondition mThingsToDo;
|
||||
std::vector<std::pair<Document *, Stage> > mDocuments;
|
||||
|
||||
QTimer* mTimer;
|
||||
bool mShouldStop;
|
||||
|
||||
public:
|
||||
|
||||
Loader();
|
||||
|
||||
QWaitCondition& hasThingsToDo();
|
||||
|
||||
void stop();
|
||||
|
||||
private slots:
|
||||
|
||||
void load();
|
||||
|
|
Loading…
Reference in a new issue