Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-12223

Strange results when using QFileInfo with paths which do not contain a filename.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P2: Important
    • 4.7.1
    • 4.5.1, 4.6.3, 4.7.0
    • None
    • MSVC8, Windows XP SP2

    Description

      There seems to be happening something strange and wholly unexpected, when I create a QFileInfo object based on a folder name (e.g. a "pure" path) and subsequently extract path and or filename info from it. In simple terms what seems to happen is that when calling e.g. canonicalPath() QFileInfo decides that everything after the last separator must be a filename, even if it is a part of the path and there is no filename. This is totally unexpected, especially in light of QFileInfo's isDir() function, which suggests that QFileInfo can handle folders as well as files.

      The code:

        QString path1 = "C:/Windows";
        QString path2 = "C:/Windows/Notepad.exe";
      
        QFileInfo info1(path1);
        QFileInfo info2(path2);
      
        path1 = info1.canonicalPath();
        path2 = info2.canonicalPath();
        QString path3 = info1.canonicalFilePath();
        QString path4 = info2.canonicalFilePath();
      
        qDebug() << "'C:/Windows' as canonicalPath():                 " << path1;
        qDebug() << "'C:/Windows/Notepad.exe' as canonicalPath():     " << path2;
        qDebug() << "'C:/Windows' as canonicalFilePath():             " << path3;
        qDebug() << "'C:/Windows/Notepad.exe' as canonicalFilePath(): " << path4;
      

      yields the following result:

      'C:/Windows' as canonicalPath():                  "C:"
      'C:/Windows/Notepad.exe' as canonicalPath():      "C:/Windows"
      'C:/Windows' as canonicalFilePath():              "C:/Windows"
      'C:/Windows/Notepad.exe' as canonicalFilePath():  "C:/Windows/Notepad.exe"
      

      I've checked the issue with the selected versions, but I'm certain this issue behaves the same in all Qt 4 versions.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            zander tho (closed Nokia identity) (Inactive)
            marcbf Marc-Berco Fuhr
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes