Qt Utilities  5.12.0
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
desktoputils.cpp
Go to the documentation of this file.
1 #include "./desktoputils.h"
2 
3 #include <QDesktopServices>
4 #include <QUrl>
5 
6 namespace DesktopUtils {
7 
13 bool openLocalFileOrDir(const QString &path)
14 {
15 #ifdef Q_OS_WIN32
16  // backslashes are commonly used under Windows
17  // -> replace backslashes with slashes to support Windows paths
18  QString tmp(path);
19  tmp.replace(QChar('\\'), QChar('/'));
20  QUrl url(QStringLiteral("file:///"));
21  url.setPath(tmp, QUrl::DecodedMode);
22  return QDesktopServices::openUrl(url);
23 #else
24  QUrl url(QStringLiteral("file://"));
25  url.setPath(path, QUrl::DecodedMode);
26  return QDesktopServices::openUrl(url);
27 #endif
28 }
29 } // namespace DesktopUtils
bool QT_UTILITIES_EXPORT openLocalFileOrDir(const QString &path)
Shows the specified file or directory using the default file browser.