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 can not open file with bad symbols
QtWS25 Last Chance

Qml Image can not open file with bad symbols

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 3 Posters 2.0k 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.
  • E Offline
    E Offline
    Elnur_Ismailzada
    wrote on last edited by
    #1

    Hi!
    How can I open an image with symbols '%' or '&' etc?

    import QtQuick 2.9
    import QtQuick.Window 2.2
    Window {
        visible: true
        width: 640
        height: 480
    
        Image {
            source: "file:////home/elnur/&'Test%25'.jpg"
        }
    }
    

    Error:

    qrc:/main.qml:20:5: QML Image: Cannot open: file:////home/elnur/&'Test%25'.jpg
    
    JonBJ 1 Reply Last reply
    0
    • E Elnur_Ismailzada

      Hi!
      How can I open an image with symbols '%' or '&' etc?

      import QtQuick 2.9
      import QtQuick.Window 2.2
      Window {
          visible: true
          width: 640
          height: 480
      
          Image {
              source: "file:////home/elnur/&'Test%25'.jpg"
          }
      }
      

      Error:

      qrc:/main.qml:20:5: QML Image: Cannot open: file:////home/elnur/&'Test%25'.jpg
      
      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @Elnur_Ismailzada
      What is the actual name on disk of your //home/elnur/&'Test%25'.jpg file? I'd be surprised if it actually has those characters in it...?

      E 1 Reply Last reply
      0
      • JonBJ JonB

        @Elnur_Ismailzada
        What is the actual name on disk of your //home/elnur/&'Test%25'.jpg file? I'd be surprised if it actually has those characters in it...?

        E Offline
        E Offline
        Elnur_Ismailzada
        wrote on last edited by
        #3

        @JonB this is the actual name of the file. User can enter any file name. It is test.

        Pablo J. RoginaP 1 Reply Last reply
        0
        • E Elnur_Ismailzada

          @JonB this is the actual name of the file. User can enter any file name. It is test.

          Pablo J. RoginaP Offline
          Pablo J. RoginaP Offline
          Pablo J. Rogina
          wrote on last edited by
          #4

          @Elnur_Ismailzada said in Qml Image can not open file with bad symbols:

          User can enter any file name. It is test.

          User should enter a valid file name, depending on underlying OS... :-)

          Anyway, I guess you should use URL encoding to avoid such situations, see url QML Basic Type

          source: encodeURIComponent("/tmp/test#1.png")
          

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          E 1 Reply Last reply
          3
          • Pablo J. RoginaP Pablo J. Rogina

            @Elnur_Ismailzada said in Qml Image can not open file with bad symbols:

            User can enter any file name. It is test.

            User should enter a valid file name, depending on underlying OS... :-)

            Anyway, I guess you should use URL encoding to avoid such situations, see url QML Basic Type

            source: encodeURIComponent("/tmp/test#1.png")
            
            E Offline
            E Offline
            Elnur_Ismailzada
            wrote on last edited by
            #5

            @Pablo-J.-Rogina I tried encodeURIComponent. Error:

            qrc:/main.qml:20:5: QML Image: Cannot open: file:////home/elnur/&'Тест%2525'.jpg
            
            Pablo J. RoginaP 1 Reply Last reply
            0
            • E Elnur_Ismailzada

              @Pablo-J.-Rogina I tried encodeURIComponent. Error:

              qrc:/main.qml:20:5: QML Image: Cannot open: file:////home/elnur/&'Тест%2525'.jpg
              
              Pablo J. RoginaP Offline
              Pablo J. RoginaP Offline
              Pablo J. Rogina
              wrote on last edited by Pablo J. Rogina
              #6

              @Elnur_Ismailzada could you please post your whole source code? I can see 4 / (slashes) which is suspicious

              file:////home/elnur/...

              Upvote the answer(s) that helped you solve the issue
              Use "Topic Tools" button to mark your post as Solved
              Add screenshots via postimage.org
              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

              E 1 Reply Last reply
              0
              • Pablo J. RoginaP Pablo J. Rogina

                @Elnur_Ismailzada could you please post your whole source code? I can see 4 / (slashes) which is suspicious

                file:////home/elnur/...

                E Offline
                E Offline
                Elnur_Ismailzada
                wrote on last edited by
                #7

                @Pablo-J.-Rogina Thank you for your time and help. I made a mistake.
                Answer:

                import QtQuick 2.9
                import QtQuick.Window 2.2
                
                Window {
                    visible: true
                    width: 640
                    height: 480
                
                    Image {
                        id: image
                
                        Component.onCompleted: {
                            source = "file://" + encodeURIComponent("/home/elnur/&'Test%25'.jpg")
                        }
                    }
                }
                
                1 Reply Last reply
                1

                • Login

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