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

QFileInfo::fileName should return an empty QString on an empty file name.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.16
    • Core: I/O
    • None
    • Windows

    Description

      While constructing a QFileInfo with QFileInfo::QFileInfo(const QDir &dir, const QString &file) with a default constructed QDir and QString (both empty), calling QFileInfo::fileName() returns "." instead of an empty QString. Here's an example:

      // provided variables that turned out to be empty
      QDir emptyDir;
      QString emptyFile;
      
      QFileInfo fileInfo(emptyDir, emptyFile);
      
      if(fileInfo.fileName().isEmpty()) { // this check failes, fileName is actually "."
          // do something
      }

      QDir("") becoming "." is sane and documented:

      https://doc.qt.io/qt-6/qdir.html#QDir-1
      If path is empty the program's working directory, ("."), is used

      But I would think QFileInfo(..., file).fileName() == file should be true

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            luiscesena Luis Andres Cesena Olvera
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes