summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/qml/qmlengine.cpp2
-rw-r--r--src/declarative/util/qmlpixmapcache.cpp28
-rw-r--r--src/declarative/util/qmlpixmapcache_p.h3
-rw-r--r--tools/qmlviewer/qmlviewer.cpp2
4 files changed, 22 insertions, 13 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;
diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp
index 7aa3a40..1566473 100644
--- a/tools/qmlviewer/qmlviewer.cpp
+++ b/tools/qmlviewer/qmlviewer.cpp
@@ -364,7 +364,7 @@ public:
} else {
manager->setCache(0);
}
- qDebug() << "created new manager for" << parent;
+ qDebug() << "created new network access manager for" << parent;
return manager;
}