PDA

View Full Version : QML Image: Failed to get image from provider



mismael85
17th May 2011, 11:43
Hi everybody,

I have a problem when importing images from C++ into QML

QML Image: Failed to get image from provider

//main.cpp

QmlApplicationViewer viewer;
QDeclarativeEngine * engine = viewer.engine();
engine->addImageProvider(QLatin1String("thumbnail"), new ContactsImageProvider);

//QML delegate file

Image {
id: personPhoto

height: 75
width: 75
source: "image://thumbnail/" + contactId
anchors.left: parent.left
}

//ContactsImageProvider

ContactsImageProvider::ContactsImageProvider()
:QDeclarativeImageProvider(QDeclarativeImageProvid er::Image)
{
m_contactsManager = new QContactManager;
}

ContactsImageProvider::~ContactsImageProvider()
{
delete m_contactsManager;
}

QImage ContactsImageProvider::requestImage(const QString& id, QSize* size, const QSize& requestedSize)
{
QContact contact = m_contactsManager->contact(id.toUInt());
QContactThumbnail thumb = contact.detail(QContactThumbnail::DefinitionName);
QImage thumbnail = thumb.thumbnail();
if(!thumbnail.isNull())
{
return thumbnail;
}
return QImage();
}


I always got the following error

QML Image: Failed to get image from provider
is there a solution?

awfan
13th December 2012, 16:37
may be id ==-1? when item is invisible.