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

QDir::exists() returns true if QDir was constructed with an empty path

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Out of scope
    • Icon: Not Evaluated Not Evaluated
    • None
    • 4.8.4
    • Core: I/O
    • None
    • Windows 7

      If you construct a QDir with a junk string, like this:

      QString s = "junk";
      QDir dir(s);
      bool exists = dir.exists(); // false - correct
      

      The exists() test will return false (correct).

      But if you pass an empty string to the constructor, exists() will always return true;

       
      QString s = "";
      QDir dir(s);
      bool exists = dir.exists(); // true - incorrect!
      

      The workaround is to construct the QDir using the default constructor and use the setPath function to initialize it:

       
      QString s = "";
      QDir dir;
      dir.setPath(s);
      bool exists = dir.exists(); // false - correct
      

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

            Unassigned Unassigned
            danny77uk Daniel
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes