From 35175b8fa5f8be93b147f57a247b8e52f28ee8cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Martins?= Date: Fri, 15 May 2015 20:03:18 +0100 Subject: Introduce QDir::listSeparator() Qt should help abstract such platform differences. This ifdef is proliferating in user code (seen a few times in KDE) and even in Qt code (qstandardpaths.cpp). [ChangeLog][QtCore][QDir] Added listSeparator(). Change-Id: Icad082a51c8efd5d63f7af9bbaedbe4bc15b8937 Reviewed-by: Konstantin Ritt Reviewed-by: Marc Mutz Reviewed-by: Thiago Macieira --- src/corelib/io/qdir.cpp | 12 ++++++++++++ src/corelib/io/qdir.h | 11 ++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index 9b1ec3917a..8b3dd5d82f 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -1826,6 +1826,8 @@ QFileInfoList QDir::drives() underlying operating system. If you want to display paths to the user using their operating system's separator use toNativeSeparators(). + + \sa listSeparator() */ QChar QDir::separator() { @@ -1836,6 +1838,16 @@ QChar QDir::separator() #endif } +/*! + \fn QDir::listSeparator() + \since 5.6 + + Returns the native path list separator: ':' under Unix + and ';' under Windows. + + \sa separator() +*/ + /*! Sets the application's current working directory to \a path. Returns \c true if the directory was successfully changed; otherwise diff --git a/src/corelib/io/qdir.h b/src/corelib/io/qdir.h index e622011f98..b6946eba65 100644 --- a/src/corelib/io/qdir.h +++ b/src/corelib/io/qdir.h @@ -177,7 +177,16 @@ public: static QFileInfoList drives(); - static QChar separator(); + Q_DECL_CONSTEXPR static inline QChar listSeparator() Q_DECL_NOTHROW + { +#if defined(Q_OS_WIN) + return QLatin1Char(';'); +#else + return QLatin1Char(':'); +#endif + } + + static QChar separator(); // ### Qt6: Make it inline static bool setCurrent(const QString &path); static inline QDir current() { return QDir(currentPath()); } -- cgit v1.2.3