Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Change in behavior for argument parsing between Qt 5.4.1 and Qt 5.12.3 on Windows?

Change in behavior for argument parsing between Qt 5.4.1 and Qt 5.12.3 on Windows?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 387 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Thuan_FirelightT Offline
    Thuan_FirelightT Offline
    Thuan_Firelight
    wrote on last edited by
    #1

    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?

    jsulmJ 1 Reply Last reply
    0
    • Thuan_FirelightT Thuan_Firelight

      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?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • Thuan_FirelightT Offline
        Thuan_FirelightT Offline
        Thuan_Firelight
        wrote on last edited by Thuan_Firelight
        #3

        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

        1 Reply Last reply
        0
        • Thuan_FirelightT Offline
          Thuan_FirelightT Offline
          Thuan_Firelight
          wrote on last edited by
          #4

          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().

          1 Reply Last reply
          0
          • Thuan_FirelightT Offline
            Thuan_FirelightT Offline
            Thuan_Firelight
            wrote on last edited by
            #5

            Is this new behavior a bug or has anyone successfully used the QCoreApplication::arguments() function in a meaningful way on Windows?

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved