Unsolved Change in behavior for argument parsing between Qt 5.4.1 and Qt 5.12.3 on Windows?
-
Hi all,
wondering if anyone has noticed that there is a change in behavior between Qt version with regards to what QCoreApplication::arguments() returns?
In Qt 5.4.1, it was returning what we expected, first argument was the application path, followed by any single dash options.
In Qt 5.12.3, it was returning seemingly unknown garbage (single character "C" for the first argument).Stepping through the code, it seems to have something to do with modified arguments and Qt's documentation is not very helpful in explaining how to get the arguments.
On Windows, the list is built from the argc and argv parameters only if modified argv/argc parameters are passed to the constructor. In that case, encoding problems might occur. Otherwise, the arguments() are constructed from the return value of GetCommandLine(). 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.
Note 5.4.1 and 5.12.3 both have similar text in the function description for QCoreApplication::arguments() but behavior is drastically different.
Can someone explain what needs to be done?
-
@thuan_firelight Can you show your code where you read the arguments and what parameters do you pass to your app? Then others can try to reproduce.
-
Hi sure, it has a few different bits hopefully would be sufficient to demonstrate the issue.
The program main entry point:
my_application.cpp
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow ) { return MyApplication::launchGUI(__argc, (char**)__wargv); }
the above calls into a static function MyApplication::launchGUI which does the below:
int FMODStudioTool::launchGUI( int &argc, char **argv ) { Application app(argc, argv); app.setAttribute(Qt::AA_EnableHighDpiScaling); return app.exec(); }
The constructor of Application is as follows:
Application::Application(int &argc, char **argv) : QApplication(argc, argv, true) { foreach(const QString& arg, QCoreApplication::instance()->arguments()) qDebug() << arg; }
For the Qt 5.4.1, it was compiled using VS2012 and for Qt 5.12.3 it was compiled using VS2017. In both instances, I am using the "Command Arguments" field in the "Debugging" section and passing -script-server-port=3664
-
I did a bit of stepping through the code, it seems to consider the arguments modified in the isArgvModified() function in QCoreApplication.cpp the argc count was 1 but __argv was null. As a result the origArgv was null and arguments() ended up not doing what it used to do which returns a list built from GetCommandLine().
-
Is this new behavior a bug or has anyone successfully used the QCoreApplication::arguments() function in a meaningful way on Windows?