Fix remote image loading for AnimatedSprite
authorAlan Alpert <aalpert@rim.com>
Tue, 26 Feb 2013 21:50:51 +0000 (13:50 -0800)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 12 Mar 2013 22:25:37 +0000 (23:25 +0100)
The Sprite generated behind the scenes had no QmlEngine associated, and
the engine is needed by QQuickPixmap for async loading.

Task-number: QTBUG-28086
Change-Id: Ibf3b03c54b339fe8f44201dc6fcb507e5274bbec
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
src/quick/items/qquickanimatedsprite.cpp
src/quick/items/qquicksprite.cpp
src/quick/items/qquickspriteengine.cpp

index 343cac5..f09e9bb 100644 (file)
@@ -365,7 +365,7 @@ QQuickAnimatedSprite::QQuickAnimatedSprite(QQuickItem *parent) :
     QQuickItem(parent)
     , m_node(0)
     , m_material(0)
-    , m_sprite(new QQuickSprite)
+    , m_sprite(new QQuickSprite(this))
     , m_spriteEngine(0)
     , m_curFrame(0)
     , m_pleaseReset(false)
@@ -540,7 +540,7 @@ QSGGeometryNode* QQuickAnimatedSprite::buildNode()
 
     m_material = new QQuickAnimatedSpriteMaterial();
 
-    QImage image = m_spriteEngine->assembledImage();
+    QImage image = m_spriteEngine->assembledImage(); //Engine prints errors if there are any
     if (image.isNull())
         return 0;
     m_sheetSize = QSizeF(image.size());
index 1359338..b413830 100644 (file)
@@ -254,8 +254,15 @@ int QQuickSprite::variedDuration() const //Deals with precedence when multiple d
 void QQuickSprite::startImageLoading()
 {
     m_pix.clear(this);
-    if (!m_source.isEmpty())
-        m_pix.load(qmlEngine(this), m_source);
+    if (!m_source.isEmpty()) {
+        QQmlEngine *e = qmlEngine(this);
+        if (!e) { //If not created in QML, you must set the QObject parent to the QML element so this can work
+            e = qmlEngine(parent());
+            if (!e)
+                qWarning() << "QQuickSprite: Cannot find QQmlEngine - this class is only for use in QML and may not work";
+        }
+        m_pix.load(e, m_source);
+    }
 }
 
 QT_END_NAMESPACE
index 4c7be3b..aa93d31 100644 (file)
@@ -328,6 +328,7 @@ QQuickPixmap::Status QQuickSpriteEngine::status()//Composed status of all Sprite
     null = loading = ready = 0;
     foreach (QQuickSprite* s, m_sprites) {
         switch (s->m_pix.status()) {
+            // ### Maybe add an error message here, because this null shouldn't be reached but when it does, the image fails without an error message.
             case QQuickPixmap::Null : null++; break;
             case QQuickPixmap::Loading : loading++; break;
             case QQuickPixmap::Error : return QQuickPixmap::Error;