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. How to parse an command line argument string into a QStringList for QProcess ?
Forum Updated to NodeBB v4.3 + New Features

How to parse an command line argument string into a QStringList for QProcess ?

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 2.4k Views 3 Watching
  • 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.
  • JonBJ JonB

    @lansing
    In this case you would be far better generating the list of separate arguments which QProcess::start() wants, rather than making a string as you do now.

    QString executable = "x264.exe";
    QStringList arguments =  (QStringList() << "-i" << "xxxx" << "-o" << "test.mp4");
    process->start(executable, arguments);
    
    L Offline
    L Offline
    lansing
    wrote on last edited by
    #3

    @JonB

    The command line will be entered by the users.

    mrjjM 1 Reply Last reply
    0
    • L lansing

      @JonB

      The command line will be entered by the users.

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @lansing
      Hi
      And how does the user enter them ?

      I mean via some GUI or via actual command line parameters to your app`?

      L 1 Reply Last reply
      0
      • mrjjM mrjj

        @lansing
        Hi
        And how does the user enter them ?

        I mean via some GUI or via actual command line parameters to your app`?

        L Offline
        L Offline
        lansing
        wrote on last edited by
        #5

        @mrjj

        I have a gui with a textarea for the entry

        mrjjM 1 Reply Last reply
        0
        • L lansing

          @mrjj

          I have a gui with a textarea for the entry

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #6

          @lansing
          ok so user type one parameter pr line or does it come
          like par1=1 par2=2 on same line ?

          So we need to find way to split it into elements and
          often we can split on space or or new line.

          L 1 Reply Last reply
          0
          • mrjjM mrjj

            @lansing
            ok so user type one parameter pr line or does it come
            like par1=1 par2=2 on same line ?

            So we need to find way to split it into elements and
            often we can split on space or or new line.

            L Offline
            L Offline
            lansing
            wrote on last edited by
            #7

            @mrjj

            The commandline will be entered by the user in one line, without the executable at the start of the line.

            -i xxxxx -o "D:\my test.mp4"

            I tried splitting it by space but it failed when I included a file path.

            mrjjM JonBJ 2 Replies Last reply
            0
            • L lansing

              @mrjj

              The commandline will be entered by the user in one line, without the executable at the start of the line.

              -i xxxxx -o "D:\my test.mp4"

              I tried splitting it by space but it failed when I included a file path.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #8

              @lansing
              Why not just use multiple LineEdits?

              Input:   [              ]
              output:[              ]
              

              and then add -i and -o yourself when you build the QStringList

              L 1 Reply Last reply
              0
              • mrjjM mrjj

                @lansing
                Why not just use multiple LineEdits?

                Input:   [              ]
                output:[              ]
                

                and then add -i and -o yourself when you build the QStringList

                L Offline
                L Offline
                lansing
                wrote on last edited by lansing
                #9

                @mrjj

                I think you're right, separating input/output file path from the argument string will resolve headache like this. Then the argument string can be easily splitted by space and put into a QStringList.

                1 Reply Last reply
                0
                • Chris KawaC Offline
                  Chris KawaC Offline
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on last edited by
                  #10

                  There's also QCommandLineParser class that can take care of all the spacing, quoting and parsing problems for you.

                  1 Reply Last reply
                  1
                  • L lansing

                    @mrjj

                    The commandline will be entered by the user in one line, without the executable at the start of the line.

                    -i xxxxx -o "D:\my test.mp4"

                    I tried splitting it by space but it failed when I included a file path.

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by JonB
                    #11

                    @lansing said in How to parse an command line argument string into a QStringList for QProcess ?:

                    The commandline will be entered by the user in one line

                    Then instead of using the deprecated QProcess::start() which accepted a string you will want to use the new [static]QStringList QProcess::splitCommand(QStringView command), which effectively exposes the function to do the splitting into arguments that the old start() used to offer.

                    L 1 Reply Last reply
                    2
                    • JonBJ JonB

                      @lansing said in How to parse an command line argument string into a QStringList for QProcess ?:

                      The commandline will be entered by the user in one line

                      Then instead of using the deprecated QProcess::start() which accepted a string you will want to use the new [static]QStringList QProcess::splitCommand(QStringView command), which effectively exposes the function to do the splitting into arguments that the old start() used to offer.

                      L Offline
                      L Offline
                      lansing
                      wrote on last edited by
                      #12

                      @JonB

                      Thanks it worked like magic.

                      QString executable = "x264.exe";
                      QString arguments = " -i xxxxx -o test.mp4";
                      QStringList argumentsList =  QProcess::splitCommand(arguments);
                      process->start(executable, argumentsList );
                      
                      1 Reply Last reply
                      1

                      • Login

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