Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML Image: Failed to get image from provider
Forum Updated to NodeBB v4.3 + New Features

QML Image: Failed to get image from provider

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Subuday
    wrote on 3 May 2019, 15:43 last edited by
    #1

    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
    
        }
    }
    
    
    K 1 Reply Last reply 3 May 2019, 16:04
    0
    • S Subuday
      3 May 2019, 15:43

      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
      
          }
      }
      
      
      K Offline
      K Offline
      KillerSmath
      wrote on 3 May 2019, 16:04 last edited by KillerSmath 5 Mar 2019, 16:07
      #2

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

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

      @Computer Science Student - Brazil
      Web Developer and Researcher
      “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

      S 1 Reply Last reply 3 May 2019, 18:12
      2
      • K KillerSmath
        3 May 2019, 16:04

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

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

        S Offline
        S Offline
        Subuday
        wrote on 3 May 2019, 18:12 last edited by
        #3

        @KillerSmath Thank you!

        1 Reply Last reply
        0

        1/3

        3 May 2019, 15:43

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved