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

QFileInfo::isRoot() unexpected behavior

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.15
    • Fix Version/s: None
    • Labels:
      None
    • Platform/s:
      Windows

      Description

      The behavior of QFileInfo::isRoot() confuses a bit.

      #include <QCoreApplication>
      
      #include <QFileInfo>
      #include <QDir>
      #include <QDebug>
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
      
          auto foo = [](const QString &path) {
              QFileInfo fi{path};
              qDebug() << path << fi.canonicalFilePath();
              qDebug() << fi.isRoot();
              qDebug() << QDir(fi.canonicalFilePath()).isRoot();
          };
      
          foo("C:\\");
          foo("C:\\test\\..\\");
          foo("C:\\..\\");
      
          return a.exec();
      }
      

      The output is following:

      "C:\\" "C:/"
      true
      true
      "C:\\test\\..\\" "C:/"
      false
      true
      "C:\\..\\" "C:/"
      false
      true
      

      Shall the result of QFileInfo::isRoot() for the same canonical path be the same?

        Attachments

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

          Activity

            People

            Assignee:
            thiago Thiago Macieira
            Reporter:
            aleksey_lysenko Aleksey Lysenko
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes