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

QFileSystemModel with wrong path of top-directory of a drive

    XMLWordPrintable

Details

    • Windows

    Description

      On windows-systems, QFileSystemModel creates wrong path of top-directories.
      The created node contains "C:"  instead of "C:\"
      And "C:" refers to the current-directory instead of the top-level directory.

       

         // EXAMPLE:     BUG: you want C:\  but you get the current working directory
         SetCurrentDirectory(L"C:\\Windows");  
         QFileSystemModel* pModel = new QFileSystemModel(nullptr);
         QFileInfo  buggyInfo     = pModel->fileInfo(pModel->index("C:\\", 0)); // try to get fileInfo of C:\   (top-directory)
         // buggyInfo:  fileEntry.m_filePath="C:"  /  fileEntry.m_nativeFilePath="\\?\C:\Windows"
         QString    txtWrongPath  = buggyInfo.absoluteFilePath();  // "C:/Windows"
         delete pModel;
      

       

         // second example
         // the parent of "C:/Windows"  should not be "C:/Solutions/250204_qt_FileSystemModel"
         QFileSystemModel* pModel = new QFileSystemModel(nullptr);
         pModel->setRootPath("");
         pModel->sort(0, Qt::AscendingOrder);
         QModelIndex testIndex     = pModel->index("C:\\Windows", 0);
         QFileInfo   correctInfo   = pModel->fileInfo(testIndex);
         QString     txtPath       = correctInfo.absoluteFilePath(); // "C:/Windows"
         QFileInfo   infoParent    = pModel->fileInfo(testIndex.parent());
         QString     txtParentFile = infoParent.absoluteFilePath(); //  "C:/Solutions/250204_qt_FileSystemModel/QtFileSystemModelTest"
         QString     txtParentPath = infoParent.absolutePath();     //  "C:/Solutions/250204_qt_FileSystemModel"
      
      qtbase-v5.15.13\src\widgets\dialogs\qfilesystemmodel.cpp
      QFileSystemModelPrivate::QFileSystemNode *QFileSystemModelPrivate::node(const QString &path, bool fetch) 
        with path = "c:\"   results in
        node->info->mFileInfo.d_ptr.d->fileEntry.m_filePath = "C:"
        node->info->mFileInfo.d_ptr.d->fileEntry.m_nativeFilePath = "\\?\C:\Users\XXX\AppData\Roaming\XXX"
      

      Attachments

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

        Activity

          People

            owolff Oliver Wolff
            stefan_p_rs stefan partheymueller
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes