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)
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());
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
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;