diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2024-01-04 21:02:45 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2024-02-01 22:06:12 +0000 |
commit | 2a8b27bf6c523de6f3f466f8062279c093940a60 (patch) | |
tree | 2b0093f8d11b3ef560daca57fd6fcfffc789409c /src/gui/itemmodels/qfilesystemmodel_p.h | |
parent | 0211dfd92bcaa5a3a4c1ce94e13fcfd9c49e9c6d (diff) |
QFileSystemModel: don't crash with setIconProvider(nullptr)
The method takes a pointer, so the code shouldn't crash when passed a
nullptr.
QFileInfoGatherer::getInfo() still needs to generate a descriptive
string for the file, so we refactor QAbstractFileIconProvider::type()
to put the implementation into a reusable static function
QAbstractFileIconProviderPrivate::getFileType(const QFileInfo &info).
This unfortunately involves constructing a QMimeDatabase on the fly,
but the docs say that is fine.
Drive-by change: use nullptr instead of `0` for pointers.
Pick-to: 6.5 6.6 6.7
Fixes: QTBUG-99178
Change-Id: Ia32ea0a26701d593e74fbecced7be8d9e0aa0f52
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/gui/itemmodels/qfilesystemmodel_p.h')
-rw-r--r-- | src/gui/itemmodels/qfilesystemmodel_p.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/gui/itemmodels/qfilesystemmodel_p.h b/src/gui/itemmodels/qfilesystemmodel_p.h index 7c9e41622e..e01b0d56e6 100644 --- a/src/gui/itemmodels/qfilesystemmodel_p.h +++ b/src/gui/itemmodels/qfilesystemmodel_p.h @@ -150,8 +150,12 @@ public: return visibleChildren.indexOf(childName); } void updateIcon(QAbstractFileIconProvider *iconProvider, const QString &path) { + if (!iconProvider) + return; + if (info) info->icon = iconProvider->icon(QFileInfo(path)); + for (QFileSystemNode *child : std::as_const(children)) { //On windows the root (My computer) has no path so we don't want to add a / for nothing (e.g. /C:/) if (!path.isEmpty()) { @@ -165,6 +169,9 @@ public: } void retranslateStrings(QAbstractFileIconProvider *iconProvider, const QString &path) { + if (!iconProvider) + return; + if (info) info->displayType = iconProvider->type(QFileInfo(path)); for (QFileSystemNode *child : std::as_const(children)) { |