diff options
author | Martin Jones <martin.jones@nokia.com> | 2010-08-23 00:32:02 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2010-08-23 00:32:02 (GMT) |
commit | 1690ad91cc9e686e688aa7832a16cbf2c9336948 (patch) | |
tree | 1f64ade5de926e018ed86bbe02ed0c956e450060 | |
parent | 0303d8da8555ccbf28ee4dcdb5367302ed940534 (diff) | |
download | Qt-1690ad91cc9e686e688aa7832a16cbf2c9336948.zip Qt-1690ad91cc9e686e688aa7832a16cbf2c9336948.tar.gz Qt-1690ad91cc9e686e688aa7832a16cbf2c9336948.tar.bz2 |
Fix crach in synchronization of ListModel in WorkerThread.
Task-number: QTBUG-13039
Reviewed-by: Aaron Kennedy
-rw-r--r-- | src/declarative/util/qdeclarativelistmodelworkeragent.cpp | 16 | ||||
-rw-r--r-- | src/declarative/util/qdeclarativelistmodelworkeragent_p.h | 4 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/declarative/util/qdeclarativelistmodelworkeragent.cpp b/src/declarative/util/qdeclarativelistmodelworkeragent.cpp index 534c923..498de6d 100644 --- a/src/declarative/util/qdeclarativelistmodelworkeragent.cpp +++ b/src/declarative/util/qdeclarativelistmodelworkeragent.cpp @@ -187,12 +187,17 @@ void QDeclarativeListModelWorkerAgent::sync() s->data = data; s->list = m_copy; data.changes.clear(); + + mutex.lock(); QCoreApplication::postEvent(this, s); + syncDone.wait(&mutex); + mutex.unlock(); } bool QDeclarativeListModelWorkerAgent::event(QEvent *e) { if (e->type() == QEvent::User) { + QMutexLocker locker(&mutex); Sync *s = static_cast<Sync *>(e); const QList<Change> &changes = s->data.changes; @@ -202,13 +207,18 @@ bool QDeclarativeListModelWorkerAgent::event(QEvent *e) FlatListModel *orig = m_orig->m_flat; FlatListModel *copy = s->list->m_flat; - if (!orig || !copy) + if (!orig || !copy) { + syncDone.wakeAll(); return QObject::event(e); - + } + orig->m_roles = copy->m_roles; orig->m_strings = copy->m_strings; orig->m_values = copy->m_values; + syncDone.wakeAll(); + locker.unlock(); + for (int ii = 0; ii < changes.count(); ++ii) { const Change &change = changes.at(ii); switch (change.type) { @@ -229,6 +239,8 @@ bool QDeclarativeListModelWorkerAgent::event(QEvent *e) if (cc) emit m_orig->countChanged(); + } else { + syncDone.wakeAll(); } } diff --git a/src/declarative/util/qdeclarativelistmodelworkeragent_p.h b/src/declarative/util/qdeclarativelistmodelworkeragent_p.h index 1622144..01da374 100644 --- a/src/declarative/util/qdeclarativelistmodelworkeragent_p.h +++ b/src/declarative/util/qdeclarativelistmodelworkeragent_p.h @@ -57,6 +57,8 @@ #include <QtScript/qscriptvalue.h> #include <QtGui/qevent.h> +#include <QMutex> +#include <QWaitCondition> QT_BEGIN_HEADER @@ -142,6 +144,8 @@ private: QAtomicInt m_ref; QDeclarativeListModel *m_orig; QDeclarativeListModel *m_copy; + QMutex mutex; + QWaitCondition syncDone; }; QT_END_NAMESPACE |