diff options
author | Bea Lam <bea.lam@nokia.com> | 2010-04-09 06:01:26 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2010-04-09 06:02:30 (GMT) |
commit | 79832f2156745ee2c6608ce7425fb2350b56f18d (patch) | |
tree | 6d43b0a3ae692cc5b580c828bf8be063277292c9 /src/declarative | |
parent | 6f796adeb7ba44791ca4faf144defac15b560fd0 (diff) | |
download | Qt-79832f2156745ee2c6608ce7425fb2350b56f18d.zip Qt-79832f2156745ee2c6608ce7425fb2350b56f18d.tar.gz Qt-79832f2156745ee2c6608ce7425fb2350b56f18d.tar.bz2 |
Make sure WorkerScript thread is stopped on deletion. This also fixes
the leaking of the worker agent in ListModel.
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/qml/qdeclarativeworkerscript.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/declarative/qml/qdeclarativeworkerscript.cpp b/src/declarative/qml/qdeclarativeworkerscript.cpp index caf680e..9e137b5 100644 --- a/src/declarative/qml/qdeclarativeworkerscript.cpp +++ b/src/declarative/qml/qdeclarativeworkerscript.cpp @@ -107,6 +107,10 @@ class QDeclarativeWorkerScriptEnginePrivate : public QObject { Q_OBJECT public: + enum WorkerEventTypes { + WorkerDestroyEvent = QEvent::User + 100 + }; + QDeclarativeWorkerScriptEnginePrivate(QDeclarativeEngine *eng); struct ScriptEngine : public QDeclarativeScriptEngine @@ -159,6 +163,9 @@ public: static QScriptValue onMessage(QScriptContext *ctxt, QScriptEngine *engine); static QScriptValue sendMessage(QScriptContext *ctxt, QScriptEngine *engine); +signals: + void stopThread(); + protected: virtual bool event(QEvent *); @@ -246,6 +253,9 @@ bool QDeclarativeWorkerScriptEnginePrivate::event(QEvent *event) WorkerLoadEvent *workerEvent = static_cast<WorkerLoadEvent *>(event); processLoad(workerEvent->workerId(), workerEvent->url()); return true; + } else if (event->type() == (QEvent::Type)WorkerDestroyEvent) { + emit stopThread(); + return true; } else { return QObject::event(event); } @@ -429,6 +439,7 @@ QDeclarativeWorkerScriptEngine::QDeclarativeWorkerScriptEngine(QDeclarativeEngin : QThread(parent), d(new QDeclarativeWorkerScriptEnginePrivate(parent)) { d->m_lock.lock(); + connect(d, SIGNAL(stopThread()), this, SLOT(quit()), Qt::DirectConnection); start(QThread::LowPriority); d->m_wait.wait(&d->m_lock); d->moveToThread(this); @@ -440,8 +451,10 @@ QDeclarativeWorkerScriptEngine::~QDeclarativeWorkerScriptEngine() d->m_lock.lock(); qDeleteAll(d->workers); d->workers.clear(); + QCoreApplication::postEvent(d, new QEvent((QEvent::Type)QDeclarativeWorkerScriptEnginePrivate::WorkerDestroyEvent)); d->m_lock.unlock(); + wait(); d->deleteLater(); } |