QFileSystemModel fails to locate a host from root's visible children
In QFileSystemModel, in some cases the hostname in a UNC path is converted to lower case and stored in the root node's visibleChildren. When QFileSystemModel sets the UNC path as the root path, it tries to get the row number for the host, but it didn't convert the hostname to lower case before getting the row number, which resulted in the host not found in the root node's visible children. As a result, it returns -1, an invalid row number. Change the behavior to find the node for the host using the host name case-insensitive and then get the row number. Fixes: QTBUG-71701 Pick-to: 5.15 6.0 6.1 Change-Id: Ib95c7b6d2bc22fd82f2789b7004b6fc82dfcb13b Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
This commit is contained in:
parent
c2258e85a3
commit
e253a30238
@ -391,8 +391,11 @@ QFileSystemModelPrivate::QFileSystemNode *QFileSystemModelPrivate::node(const QS
|
||||
if (absolutePath.endsWith(QLatin1Char('/')))
|
||||
trailingSeparator = QLatin1String("\\");
|
||||
int r = 0;
|
||||
QFileSystemModelPrivate::QFileSystemNode *rootNode = const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&root);
|
||||
if (!root.children.contains(host.toLower())) {
|
||||
auto rootNode = const_cast<QFileSystemModelPrivate::QFileSystemNode*>(&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);
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user