Details
-
Bug
-
Resolution: Unresolved
-
P1: Critical
-
None
-
5.15.13, 6.8.2
-
Windows 11 - Qt 5.15.13 / Windows 11 - Qt 6.8.2
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"