summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2010-04-09 06:01:26 (GMT)
committerBea Lam <bea.lam@nokia.com>2010-04-09 06:02:30 (GMT)
commit79832f2156745ee2c6608ce7425fb2350b56f18d (patch)
tree6d43b0a3ae692cc5b580c828bf8be063277292c9 /src
parent6f796adeb7ba44791ca4faf144defac15b560fd0 (diff)
downloadQt-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')
-rw-r--r--src/declarative/qml/qdeclarativeworkerscript.cpp13
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();
}