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. How to use QImage to load a file with name "#.png"?
Forum Updated to NodeBB v4.3 + New Features

How to use QImage to load a file with name "#.png"?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 5 Posters 1.1k 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.
  • N Offline
    N Offline
    NixUhs
    wrote on last edited by
    #1

    There is a file named "#.png" in my D disk
    When I use the following qml code
    Image {
    source: "file:///D:/#.png"
    }
    and I directly get an error "QML Image: Cannot open: file:///D://#.png"
    but everything is fine if I rename the file name to "1.png", how to solve this problem

    KroMignonK 1 Reply Last reply
    0
    • Swati777999S Offline
      Swati777999S Offline
      Swati777999
      wrote on last edited by
      #2

      I think the format of file path is incorrect .

      For Example,try the following:
      D:/#.png

      For more information , follow - link

      “ In order to be irreplaceable, one must always be different” – Coco Chanel

      1 Reply Last reply
      0
      • N Offline
        N Offline
        NixUhs
        wrote on last edited by
        #3

        if the path format is incorrect, rename to 1.png should be the same result.

        1 Reply Last reply
        0
        • N NixUhs

          There is a file named "#.png" in my D disk
          When I use the following qml code
          Image {
          source: "file:///D:/#.png"
          }
          and I directly get an error "QML Image: Cannot open: file:///D://#.png"
          but everything is fine if I rename the file name to "1.png", how to solve this problem

          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on last edited by
          #4

          @NixUhs said in How to use QImage to load a file with name "#.png"?:

          There is a file named "#.png" in my D disk
          When I use the following qml code
          Image {
          source: "file:///D:/#.png"
          }
          and I directly get an error "QML Image: Cannot open: file:///D://#.png"
          but everything is fine if I rename the file name to "1.png", how to solve this problem

          You have to escape hash-tag symbol with \ (cf https://bugreports.qt.io/browse/QTBUG-68635)
          Following should work:

          Image {
              source: "file:///D:/\#.png"
          }
          

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          1 Reply Last reply
          0
          • GrecKoG Offline
            GrecKoG Offline
            GrecKo
            Qt Champions 2018
            wrote on last edited by
            #5

            Or use encoreURIComponent like mentionned at the end of the url documentation.

            fcarneyF 1 Reply Last reply
            3
            • GrecKoG GrecKo

              Or use encoreURIComponent like mentionned at the end of the url documentation.

              fcarneyF Offline
              fcarneyF Offline
              fcarney
              wrote on last edited by
              #6

              @GrecKo said in How to use QImage to load a file with name "#.png"?:

              encoreURIComponent

              encodeURIComponent

              C++ is a perfectly valid school of magic.

              1 Reply Last reply
              0
              • N Offline
                N Offline
                NixUhs
                wrote on last edited by
                #7

                Solved, I use "replace(QChar('#'), "%23")" to every path QString

                source: "file:///D:/#.png" not working
                encodeURIComponent not working

                1 Reply Last reply
                0

                • Login

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