Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QML Image: Failed to get image from provider



  • 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
    
        }
    }
    
    


  • @Subuday
    Use :/icons/Icons/close.png instead of qrc:/icons/Icons/close.png

    :/ -> File path Syntax
    qrc:/ -> Url Path Syntax



  • @KillerSmath Thank you!


Log in to reply