From 1690ad91cc9e686e688aa7832a16cbf2c9336948 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 23 Aug 2010 10:32:02 +1000 Subject: Fix crach in synchronization of ListModel in WorkerThread. Task-number: QTBUG-13039 Reviewed-by: Aaron Kennedy --- .../util/qdeclarativelistmodelworkeragent.cpp | 16 ++++++++++++++-- .../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(e); const QList &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 #include +#include +#include QT_BEGIN_HEADER @@ -142,6 +144,8 @@ private: QAtomicInt m_ref; QDeclarativeListModel *m_orig; QDeclarativeListModel *m_copy; + QMutex mutex; + QWaitCondition syncDone; }; QT_END_NAMESPACE -- cgit v0.12