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
);
QmlApplicationViewer viewer;
QDeclarativeEngine * engine = viewer.engine();
engine->addImageProvider(QLatin1String("thumbnail"), new ContactsImageProvider);
To copy to clipboard, switch view to plain text mode
//QML delegate file
Image {
id: personPhoto
height: 75
width: 75
source: "image://thumbnail/" + contactId
anchors.left: parent.left
}
Image {
id: personPhoto
height: 75
width: 75
source: "image://thumbnail/" + contactId
anchors.left: parent.left
}
To copy to clipboard, switch view to plain text mode
//ContactsImageProvider
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;
}
}
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;
}
return QImage();
}
To copy to clipboard, switch view to plain text mode
I always got the following error
QML Image: Failed to get image from provider
is there a solution?
Bookmarks