QML Image: Failed to get image from provider
Hi everybody,
I have a problem when importing images from C++ into QML
Quote:
QML Image: Failed to get image from provider
//main.cpp
Code:
QmlApplicationViewer viewer;
QDeclarativeEngine * engine = viewer.engine();
engine
->addImageProvider
(QLatin1String("thumbnail"),
new ContactsImageProvider
);
//QML delegate file
Code:
Image {
id: personPhoto
height: 75
width: 75
source: "image://thumbnail/" + contactId
anchors.left: parent.left
}
//ContactsImageProvider
Code:
ContactsImageProvider::ContactsImageProvider()
:QDeclarativeImageProvider(QDeclarativeImageProvider::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;
}
}
I always got the following error
Quote:
QML Image: Failed to get image from provider
is there a solution?
Re: QML Image: Failed to get image from provider
may be id ==-1? when item is invisible.