From b67bbed1965ce9931a6280daeb1d2a05a3c905a5 Mon Sep 17 00:00:00 2001 From: Dongmei Wang Date: Fri, 9 Nov 2018 00:07:58 -0800 Subject: 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 Change-Id: Ib95c7b6d2bc22fd82f2789b7004b6fc82dfcb13b Reviewed-by: Edward Welbourne Reviewed-by: Qt CI Bot Reviewed-by: Alex Blasche (cherry picked from commit e253a30238ed1a93877780428c035d3b7a53e22a) --- .../itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests') diff --git a/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp index e814e79dbe..4fe998f43e 100644 --- a/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -226,6 +226,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(QString("\\\\localhost\\c$")); + QVERIFY(index.isValid()); + QCOMPARE(model->rootPath(), QString("//localhost/c$")); + + index = model->setRootPath(QString("\\\\localhost\\C$")); + QVERIFY(index.isValid()); + QCOMPARE(model->rootPath(), QString("//localhost/C$")); + + index = model->setRootPath(QString("\\\\LOCALHOST\\C$")); + QVERIFY(index.isValid()); + QCOMPARE(model->rootPath(), QString("//LOCALHOST/C$")); +#endif } void tst_QFileSystemModel::readOnly() -- cgit v1.2.3