diff options
author | Martin Jones <martin.jones@nokia.com> | 2010-02-05 02:43:23 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2010-02-05 02:43:23 (GMT) |
commit | 77fea35494d79661606ed6c6a0de55c03ae5cc83 (patch) | |
tree | 2b03a9685324a91b9bd091bc32720e6793188725 /src/declarative | |
parent | 2d7b0bbe0997250445c99edd93f4fe5529781b93 (diff) | |
download | Qt-77fea35494d79661606ed6c6a0de55c03ae5cc83.zip Qt-77fea35494d79661606ed6c6a0de55c03ae5cc83.tar.gz Qt-77fea35494d79661606ed6c6a0de55c03ae5cc83.tar.bz2 |
Clean up QmlImageReader thread on engine destruction.
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/qml/qmlengine.cpp | 2 | ||||
-rw-r--r-- | src/declarative/util/qmlpixmapcache.cpp | 28 | ||||
-rw-r--r-- | src/declarative/util/qmlpixmapcache_p.h | 3 |
3 files changed, 21 insertions, 12 deletions
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index ea0c054..5624da1 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -399,6 +399,8 @@ QmlContext *QmlEngine::rootContext() By implementing a factory it is possible to create custom QNetworkAccessManager with specialized caching, proxy and cookie support. + + The factory must be set before exceuting the engine. */ void QmlEngine::setNetworkAccessManagerFactory(QmlNetworkAccessManagerFactory *factory) { diff --git a/src/declarative/util/qmlpixmapcache.cpp b/src/declarative/util/qmlpixmapcache.cpp index f1c4a12..43226a6 100644 --- a/src/declarative/util/qmlpixmapcache.cpp +++ b/src/declarative/util/qmlpixmapcache.cpp @@ -113,10 +113,12 @@ private: QMutex mutex; static QHash<QmlEngine *,QmlImageReader*> readers; + static QMutex readerMutex; friend class QmlImageRequestHandler; }; QHash<QmlEngine *,QmlImageReader*> QmlImageReader::readers; +QMutex QmlImageReader::readerMutex; class QmlImageRequestHandler : public QObject @@ -252,19 +254,23 @@ QmlImageReader::QmlImageReader(QmlEngine *eng) QmlImageReader::~QmlImageReader() { + quit(); + wait(); + readerMutex.lock(); + readers.remove(engine); + readerMutex.unlock(); delete handler; } QmlImageReader *QmlImageReader::instance(QmlEngine *engine) { + readerMutex.lock(); QmlImageReader *reader = readers.value(engine); if (!reader) { - static QMutex rmutex; - rmutex.lock(); reader = new QmlImageReader(engine); readers.insert(engine, reader); - rmutex.unlock(); } + readerMutex.unlock(); return reader; } @@ -272,7 +278,7 @@ QmlImageReader *QmlImageReader::instance(QmlEngine *engine) QmlPixmapReply *QmlImageReader::getImage(const QUrl &url) { mutex.lock(); - QmlPixmapReply *reply = new QmlPixmapReply(engine, url); + QmlPixmapReply *reply = new QmlPixmapReply(this, url); jobs.append(reply); if (jobs.count() == 1 && handler) QCoreApplication::postEvent(handler, new QEvent(QEvent::User)); @@ -378,8 +384,8 @@ class QmlPixmapReplyPrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QmlPixmapReply) public: - QmlPixmapReplyPrivate(QmlEngine *e, const QUrl &u) - : QObjectPrivate(), refCount(1), url(u), status(QmlPixmapReply::Loading), loading(false), engine(e) { + QmlPixmapReplyPrivate(QmlImageReader *r, const QUrl &u) + : QObjectPrivate(), refCount(1), url(u), status(QmlPixmapReply::Loading), loading(false), reader(r) { } int refCount; @@ -387,12 +393,12 @@ public: QPixmap pixmap; // ensure reference to pixmap so QPixmapCache does not discard QmlPixmapReply::Status status; bool loading; - QmlEngine *engine; + QmlImageReader *reader; }; -QmlPixmapReply::QmlPixmapReply(QmlEngine *engine, const QUrl &url) - : QObject(*new QmlPixmapReplyPrivate(engine, url), 0) +QmlPixmapReply::QmlPixmapReply(QmlImageReader *reader, const QUrl &url) + : QObject(*new QmlPixmapReplyPrivate(reader, url), 0) { } @@ -459,7 +465,7 @@ bool QmlPixmapReply::release(bool defer) if (d->refCount == 0) { qmlActivePixmapReplies()->remove(d->url); if (d->status == Loading && !d->loading) - QmlImageReader::instance(d->engine)->cancel(this); + d->reader->cancel(this); if (defer) deleteLater(); else @@ -468,7 +474,7 @@ bool QmlPixmapReply::release(bool defer) } else if (d->refCount == 1 && d->loading) { // The only reference left is the reader thread. qmlActivePixmapReplies()->remove(d->url); - QmlImageReader::instance(d->engine)->cancel(this); + d->reader->cancel(this); } return false; diff --git a/src/declarative/util/qmlpixmapcache_p.h b/src/declarative/util/qmlpixmapcache_p.h index c202ea8..462faf6 100644 --- a/src/declarative/util/qmlpixmapcache_p.h +++ b/src/declarative/util/qmlpixmapcache_p.h @@ -53,13 +53,13 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) class QmlEngine; class QNetworkReply; +class QmlImageReader; class QmlPixmapReplyPrivate; class Q_DECLARATIVE_EXPORT QmlPixmapReply : public QObject { Q_OBJECT public: - QmlPixmapReply(QmlEngine *engine, const QUrl &url); ~QmlPixmapReply(); enum Status { Ready, Error, Unrequested, Loading }; @@ -81,6 +81,7 @@ private: void setLoading(); private: + QmlPixmapReply(QmlImageReader *reader, const QUrl &url); Q_DISABLE_COPY(QmlPixmapReply) Q_DECLARE_PRIVATE(QmlPixmapReply) friend class QmlImageRequestHandler; |