From 9b121e5579538477a1fc7c8250e5d7e875a58de8 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 30 Apr 2014 08:46:16 +0200 Subject: Windows: Use WinAPI CommandLineToArgvW() to create argv from command line. Split the Windows CE/Desktop Windows code paths in winmain. Use CommandLineToArgvW() to obtain argv[] for Desktop Windows. [ChangeLog][QtCore][Windows] Command line parsing on Windows now uses the WinAPI function CommandLineToArgvW() to exactly match the quoting of the command interpreter. Task-number: QTBUG-35432 Task-number: QTBUG-23687 Change-Id: I6743e73649d953497642f7717d3731a83ffda2a2 Reviewed-by: Oswald Buddenhagen Reviewed-by: Thiago Macieira --- src/corelib/kernel/qcorecmdlineargs_p.h | 38 ++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'src/corelib/kernel/qcorecmdlineargs_p.h') diff --git a/src/corelib/kernel/qcorecmdlineargs_p.h b/src/corelib/kernel/qcorecmdlineargs_p.h index 93c80205ab..84d9be20e5 100644 --- a/src/corelib/kernel/qcorecmdlineargs_p.h +++ b/src/corelib/kernel/qcorecmdlineargs_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -56,14 +56,34 @@ #include "QtCore/qstring.h" #include "QtCore/qstringlist.h" +#if defined(Q_OS_WIN) +# ifdef Q_OS_WIN32 +# include // first to suppress min, max macros. +# include +# else +# include "QtCore/qvector.h" +# include +# endif + QT_BEGIN_NAMESPACE -#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN32) + +static inline QStringList qWinCmdArgs(const QString &cmdLine) +{ + QStringList result; + int size; + if (wchar_t **argv = CommandLineToArgvW((const wchar_t *)cmdLine.utf16(), &size)) { + result.reserve(size); + wchar_t **argvEnd = argv + size; + for (wchar_t **a = argv; a < argvEnd; ++a) + result.append(QString::fromWCharArray(*a)); + LocalFree(argv); + } + return result; +} -QT_BEGIN_INCLUDE_NAMESPACE -# include "QtCore/qvector.h" -# include -QT_END_INCLUDE_NAMESPACE +#elif defined(Q_OS_WINCE) // Q_OS_WIN32 // template implementation of the parsing algorithm // this is used from qcoreapplication_win.cpp and the tools (rcc, uic...) @@ -149,7 +169,7 @@ static inline QStringList qCmdLineArgs(int argc, char *argv[]) return qWinCmdArgs(cmdLine); } -#else // Q_OS_WIN && !Q_OS_WINRT +#elif defined(Q_OS_WINRT) // Q_OS_WINCE static inline QStringList qCmdLineArgs(int argc, char *argv[]) { @@ -159,8 +179,10 @@ static inline QStringList qCmdLineArgs(int argc, char *argv[]) return args; } -#endif // !Q_OS_WIN || Q_OS_WINRT +#endif // Q_OS_WINRT QT_END_NAMESPACE +#endif // Q_OS_WIN + #endif // QCORECMDLINEARGS_WIN_P_H -- cgit v1.2.3