Qt Utilities  5.6.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 
12 bool openLocalFileOrDir(const QString &path)
13 {
14 #ifdef Q_OS_WIN32
15  // backslashes are commonly used under Windows
16  // -> replace backslashes with slashes to support Windows paths
17  QString tmp(path);
18  tmp.replace(QChar('\\'), QChar('/'));
19  QUrl url(QStringLiteral("file:///"));
20  url.setPath(tmp, QUrl::DecodedMode);
21  return QDesktopServices::openUrl(url);
22 #else
23  QUrl url(QStringLiteral("file://"));
24  url.setPath(path, QUrl::DecodedMode);
25  return QDesktopServices::openUrl(url);
26 #endif
27 }
28 
29 }
bool QT_UTILITIES_EXPORT openLocalFileOrDir(const QString &path)
Shows the specified file or directory using the default file browser.