diff --git a/src/gui/itemmodels/qfilesystemmodel.cpp b/src/gui/itemmodels/qfilesystemmodel.cpp index 70c274b816c..e0274e5fefe 100644 --- a/src/gui/itemmodels/qfilesystemmodel.cpp +++ b/src/gui/itemmodels/qfilesystemmodel.cpp @@ -391,8 +391,11 @@ QFileSystemModelPrivate::QFileSystemNode *QFileSystemModelPrivate::node(const QS if (absolutePath.endsWith(QLatin1Char('/'))) trailingSeparator = QLatin1String("\\"); int r = 0; - QFileSystemModelPrivate::QFileSystemNode *rootNode = const_cast(&root); - if (!root.children.contains(host.toLower())) { + auto rootNode = const_cast(&root); + auto it = root.children.constFind(host); + if (it != root.children.cend()) { + host = it.key(); // Normalize case for lookup in visibleLocation() + } else { if (pathElements.count() == 1 && !absolutePath.endsWith(QLatin1Char('/'))) return rootNode; QFileInfo info(host); diff --git a/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp index b9c44aa4c28..b6f6328acd6 100644 --- a/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -230,6 +230,21 @@ void tst_QFileSystemModel::rootPath() QCOMPARE(rootChanged.count(), oldCount + 1); QCOMPARE(model->rootDirectory().absolutePath(), newdir.path()); } + +#ifdef Q_OS_WIN + // check case insensitive root node on windows, tests QTBUG-71701 + QModelIndex index = model->setRootPath(uR"(\\localhost\c$)"_qs); + QVERIFY(index.isValid()); + QCOMPARE(model->rootPath(), u"//localhost/c$"_qs); + + index = model->setRootPath(uR"(\\localhost\C$)"_qs); + QVERIFY(index.isValid()); + QCOMPARE(model->rootPath(), u"//localhost/C$"_qs); + + index = model->setRootPath(uR"(\\LOCALHOST\C$)"_qs); + QVERIFY(index.isValid()); + QCOMPARE(model->rootPath(), u"//LOCALHOST/C$"_qs); +#endif } void tst_QFileSystemModel::readOnly()