Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Solved Qml Image can not open file with bad symbols

    QML and Qt Quick
    3
    7
    1396
    Loading More Posts
    • 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
      Elnur_Ismailzada last edited by

      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
      
      JonB 1 Reply Last reply Reply Quote 0
      • JonB
        JonB @Elnur_Ismailzada last edited by

        @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 Reply Quote 0
        • E
          Elnur_Ismailzada @JonB last edited by

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

          Pablo J. Rogina 1 Reply Last reply Reply Quote 0
          • Pablo J. Rogina
            Pablo J. Rogina @Elnur_Ismailzada last edited by

            @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 Reply Quote 3
            • E
              Elnur_Ismailzada @Pablo J. Rogina last edited by

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

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

                @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 Reply Quote 0
                • E
                  Elnur_Ismailzada @Pablo J. Rogina last edited by

                  @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 Reply Quote 1
                  • First post
                    Last post