diff options
Diffstat (limited to 'src/corelib/kernel/qcoreapplication.cpp')
-rw-r--r-- | src/corelib/kernel/qcoreapplication.cpp | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index a7b14b22b5..290248aa6d 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -103,6 +103,8 @@ # include <taskLib.h> #endif +#include <algorithm> + QT_BEGIN_NAMESPACE #ifndef QT_NO_QOBJECT @@ -397,7 +399,7 @@ QCoreApplicationPrivate::QCoreApplicationPrivate(int &aargc, char **aargv, uint argv = (char **)∅ } #ifdef Q_OS_WIN - qCopy(argv, argv + argc, origArgv); + std::copy(argv, argv + argc, origArgv); #endif #ifndef QT_NO_QOBJECT @@ -589,6 +591,8 @@ void QCoreApplicationPrivate::initLocale() Note that some arguments supplied by the user may have been processed and removed by QCoreApplication. + For more advanced command line option handling, create a QCommandLineParser. + \section1 Locale Settings On Unix/Linux Qt is configured to use the system locale settings by @@ -1950,7 +1954,6 @@ QString QCoreApplication::applicationFilePath() char buff[maximum_path+1]; if (_cmdname(buff)) { d->cachedApplicationFilePath = QDir::cleanPath(QString::fromLocal8Bit(buff)); - return d->cachedApplicationFilePath; } else { qWarning("QCoreApplication::applicationFilePath: _cmdname() failed"); // _cmdname() won't fail, but just in case, fallback to the old method @@ -1959,11 +1962,11 @@ QString QCoreApplication::applicationFilePath() if (!executables.empty()) { //We assume that there is only one executable in the folder d->cachedApplicationFilePath = dir.absoluteFilePath(executables.first()); - return d->cachedApplicationFilePath; } else { - return QString(); + d->cachedApplicationFilePath = QString(); } } + return d->cachedApplicationFilePath; #elif defined(Q_OS_MAC) QString qAppFileName_str = qAppFileName(); if(!qAppFileName_str.isEmpty()) { @@ -1982,34 +1985,38 @@ QString QCoreApplication::applicationFilePath() return d->cachedApplicationFilePath; } # endif + if (!arguments().isEmpty()) { + QString argv0 = QFile::decodeName(arguments().at(0).toLocal8Bit()); + QString absPath; + + if (!argv0.isEmpty() && argv0.at(0) == QLatin1Char('/')) { + /* + If argv0 starts with a slash, it is already an absolute + file path. + */ + absPath = argv0; + } else if (argv0.contains(QLatin1Char('/'))) { + /* + If argv0 contains one or more slashes, it is a file path + relative to the current directory. + */ + absPath = QDir::current().absoluteFilePath(argv0); + } else { + /* + Otherwise, the file path has to be determined using the + PATH environment variable. + */ + absPath = QStandardPaths::findExecutable(argv0); + } + + absPath = QDir::cleanPath(absPath); - QString argv0 = QFile::decodeName(arguments().at(0).toLocal8Bit()); - QString absPath; - - if (!argv0.isEmpty() && argv0.at(0) == QLatin1Char('/')) { - /* - If argv0 starts with a slash, it is already an absolute - file path. - */ - absPath = argv0; - } else if (argv0.contains(QLatin1Char('/'))) { - /* - If argv0 contains one or more slashes, it is a file path - relative to the current directory. - */ - absPath = QDir::current().absoluteFilePath(argv0); + QFileInfo fi(absPath); + d->cachedApplicationFilePath = fi.exists() ? fi.canonicalFilePath() : QString(); } else { - /* - Otherwise, the file path has to be determined using the - PATH environment variable. - */ - absPath = QStandardPaths::findExecutable(argv0); + d->cachedApplicationFilePath = QString(); } - absPath = QDir::cleanPath(absPath); - - QFileInfo fi(absPath); - d->cachedApplicationFilePath = fi.exists() ? fi.canonicalFilePath() : QString(); return d->cachedApplicationFilePath; #endif } @@ -2057,7 +2064,7 @@ qint64 QCoreApplication::applicationPid() As a result of this, the string given by arguments().at(0) might not be the program name on Windows, depending on how the application was started. - \sa applicationFilePath() + \sa applicationFilePath(), QCommandLineParser */ QStringList QCoreApplication::arguments() |