QML Image: Failed to get image from provider
Solved
QML and Qt Quick
-
wrote on 3 May 2019, 15:43 last edited by
I try different filePathes and Images, but it always doesn't work. But if I use an example code qt exmaple it works.
QImage MyImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) { //QImage avatar = QImage("qrc:/icons/Icons/noImage.png"); QPixmap avatar("qrc:/icons/Icons/close.png"); if(size) { *size = avatar.size(); } if(requestedSize.width() > 0 && requestedSize.height() > 0) { avatar = avatar.scaled(requestedSize.width(), requestedSize.height(), Qt::KeepAspectRatio); } return avatar.toImage();
Item { Image { id: test source: "image://avatar/23" width: 120 height: 120 } }
-
I try different filePathes and Images, but it always doesn't work. But if I use an example code qt exmaple it works.
QImage MyImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) { //QImage avatar = QImage("qrc:/icons/Icons/noImage.png"); QPixmap avatar("qrc:/icons/Icons/close.png"); if(size) { *size = avatar.size(); } if(requestedSize.width() > 0 && requestedSize.height() > 0) { avatar = avatar.scaled(requestedSize.width(), requestedSize.height(), Qt::KeepAspectRatio); } return avatar.toImage();
Item { Image { id: test source: "image://avatar/23" width: 120 height: 120 } }
wrote on 3 May 2019, 16:04 last edited by KillerSmath 5 Mar 2019, 16:07@Subuday
Use:/icons/Icons/close.png
instead ofqrc:/icons/Icons/close.png
:/ -> File path Syntax
qrc:/ -> Url Path Syntax -
@Subuday
Use:/icons/Icons/close.png
instead ofqrc:/icons/Icons/close.png
:/ -> File path Syntax
qrc:/ -> Url Path Syntaxwrote on 3 May 2019, 18:12 last edited by@KillerSmath Thank you!
3/3