aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quickcontrols/filesystemexplorer
diff options
context:
space:
mode:
authorFriedemann Kleint <[email protected]>2023-02-21 10:03:39 +0100
committerFriedemann Kleint <[email protected]>2023-02-22 08:16:55 +0100
commit211d578def6a44981b528c678f393e57472f56df (patch)
treee273f3f8a61e1c2ed9027b97a7fad3a7079a0e70 /examples/quickcontrols/filesystemexplorer
parent481f034d1c98337557c2bc8d121213f9b441ba7f (diff)
File System Explorer example: Make QMimeDatabase a static variable
QMimeDatabase is potentially expensive to initialize, avoid doing this repetitively. Amends 213e932e138d460159487a624838aa7d3bcffb4a. Task-number: QTBUG-108289 Change-Id: I66e5aeb22ffade9b86635e27b9d518c9e40aee4f Reviewed-by: Mitch Curtis <[email protected]>
Diffstat (limited to 'examples/quickcontrols/filesystemexplorer')
-rw-r--r--examples/quickcontrols/filesystemexplorer/filesystemmodel.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/examples/quickcontrols/filesystemexplorer/filesystemmodel.cpp b/examples/quickcontrols/filesystemexplorer/filesystemmodel.cpp
index 45b47737f5..e383a0ea29 100644
--- a/examples/quickcontrols/filesystemexplorer/filesystemmodel.cpp
+++ b/examples/quickcontrols/filesystemexplorer/filesystemmodel.cpp
@@ -26,12 +26,12 @@ QString FileSystemModel::readFile(const QString &filePath)
QFile file(filePath);
- const QMimeDatabase db;
- const QMimeType mime = db.mimeTypeForFile(QFileInfo(file));
-
if (file.size() >= 2'000'000)
return tr("File size is too big.\nYou can read files up to %1 MB.").arg(2);
+ static const QMimeDatabase db;
+ const QMimeType mime = db.mimeTypeForFile(QFileInfo(file));
+
// Check if the mimetype is supported and return the content.
const auto mimeTypesForFile = mime.parentMimeTypes();
for (const auto &m : mimeTypesForFile) {