Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QImageReader struggles with some paths
Qt 6.11 is out! See what's new in the release blog

QImageReader struggles with some paths

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 1.4k Views 1 Watching
  • 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.
  • MegamouseM Offline
    MegamouseM Offline
    Megamouse
    wrote on last edited by
    #1

    Hi,

    I'm using a QImageReader to get the image info.
    A path to a png ending with the following string works:

    /photo/test/Hatsune Miku Project DIVA F_10.png
    

    But the same path with a colon doesn't

    /photo/test/Hatsune Miku: Project DIVA F_10.png
    

    The QImageReader::canRead() function returns false and the errorString() returns "File not found".

    Is there some way around this?

    JonBJ 1 Reply Last reply
    0
    • MegamouseM Megamouse

      Hi,

      I'm using a QImageReader to get the image info.
      A path to a png ending with the following string works:

      /photo/test/Hatsune Miku Project DIVA F_10.png
      

      But the same path with a colon doesn't

      /photo/test/Hatsune Miku: Project DIVA F_10.png
      

      The QImageReader::canRead() function returns false and the errorString() returns "File not found".

      Is there some way around this?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Megamouse
      What platform is this on?

      1 Reply Last reply
      0
      • MegamouseM Offline
        MegamouseM Offline
        Megamouse
        wrote on last edited by
        #3

        It works if I get the QString from a QFileDialog, even though the QString is identical to the one i got as std::string, converted with QString::fromStdString();

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          How do you get the one that is a std::string ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          MegamouseM 1 Reply Last reply
          0
          • MegamouseM Offline
            MegamouseM Offline
            Megamouse
            wrote on last edited by
            #5

            I'm on Windows 11.

            This is the log:

            QString                "C:/Users/Megamouse/Pictures/Hatsune Miku: Project DIVA F_10.png"    canRead true
            QString::fromStdString "C:/Users/Megamouse/Pictures/Hatsune Miku: Project DIVA F_10.png"    canRead false
            
            JonBJ 1 Reply Last reply
            0
            • MegamouseM Megamouse

              I'm on Windows 11.

              This is the log:

              QString                "C:/Users/Megamouse/Pictures/Hatsune Miku: Project DIVA F_10.png"    canRead true
              QString::fromStdString "C:/Users/Megamouse/Pictures/Hatsune Miku: Project DIVA F_10.png"    canRead false
              
              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @Megamouse
              If you are on Windows how is either of those a legal pathname? [To be clear: Windows doesn't allow : in pathnames.] I don't know about why stdString makes any difference to the result regardless.

              1 Reply Last reply
              0
              • SGaistS SGaist

                Hi,

                How do you get the one that is a std::string ?

                MegamouseM Offline
                MegamouseM Offline
                Megamouse
                wrote on last edited by
                #7

                @SGaist said in QImageReader struggles with some paths:

                How do you get the one that is a std::string ?

                It's also not working if the path was created as QString in the first place.
                Maybe there's some hidden stuff in QString coming from QFileDialog?

                The path comes from regular c++ directory scan

                JonBJ 1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Did you try to compare the content at the lowest level ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • MegamouseM Megamouse

                    @SGaist said in QImageReader struggles with some paths:

                    How do you get the one that is a std::string ?

                    It's also not working if the path was created as QString in the first place.
                    Maybe there's some hidden stuff in QString coming from QFileDialog?

                    The path comes from regular c++ directory scan

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #9

                    @Megamouse
                    I would check again your understanding that your Windows filename contains an embedded : character.

                    For example, try to create such a filename yourself, from a program or Explorer or whatever.

                    Have a read of e.g. https://stackoverflow.com/questions/10386344/how-to-get-a-file-in-windows-with-a-colon-in-the-filename. Could the solution there be relevant to your situation, could it actually be a :-looking character which is not a :?

                    1 Reply Last reply
                    0
                    • MegamouseM Offline
                      MegamouseM Offline
                      Megamouse
                      wrote on last edited by
                      #10

                      Yes. I just did.
                      Turns out the original path has a FULLWIDTH COLON, while the other one converts it to a regular colon.
                      The QImageReader thus can't find the file.

                      JonBJ 1 Reply Last reply
                      0
                      • MegamouseM Megamouse

                        Yes. I just did.
                        Turns out the original path has a FULLWIDTH COLON, while the other one converts it to a regular colon.
                        The QImageReader thus can't find the file.

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by
                        #11

                        @Megamouse

                        Turns out the original path has a FULLWIDTH COLON, while the other one converts it to a regular colon.

                        ...which is exactly what the stackoverflow solution talks about...

                        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