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

The QDir path exists when the construct is empty

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Not Evaluated
    • Resolution: Invalid
    • Affects Version/s: 5.15.0 RC2
    • Fix Version/s: None
    • Component/s: Core: I/O
    • Labels:
      None
    • Platform/s:
      All

      Description

      When I use the following code, the output results of these are different. Only QDir outputs the information of exist. When I look at the source code, I find that it is set to the current path when its constructor is empty. The problem arises from the fact that I am still judged to exist when I use the function call passed in QDir to return null value. I think it is unreasonable for such interface design, although the current path will be used when the QDIR structure is empty is written in the official document.

      QString getConfig() {
          return "";
      }
      
      int main(int argc, char *argv[])
      {
          QCoreApplication app(argc, argv);
      
          if (QDir(getConfig()).exists()) {
              qDebug() << "QDir exist";
          }
          if (QFile((getConfig())).exists()) {
              qDebug() << "QFile exist";
          }
          if (QFileInfo(getConfig()).exists()) {
              qDebug() << "QFileInfo exist";
          }
      
          return app.exec();
      }
      

       

        Attachments

        1. bug.png
          bug.png
          68 kB
        2. setpath_directly.png
          setpath_directly.png
          162 kB
        For Gerrit Dashboard: QTBUG-95253
        # Subject Branch Project Status CR V

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes