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. Problem using QProcess with arguments that have quotes & contain spaces [Win32/64]

Problem using QProcess with arguments that have quotes & contain spaces [Win32/64]

Scheduled Pinned Locked Moved General and Desktop
14 Posts 4 Posters 23.3k 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.
  • S Offline
    S Offline
    Smar
    wrote on last edited by
    #2

    http://doc.qt.nokia.com/latest/qprocess.html#execute

    bq. On Windows, arguments that contain spaces are wrapped in quotes.

    So you don't add quotes yourself and it will work.

    1 Reply Last reply
    1
    • L Offline
      L Offline
      livingWithQt
      wrote on last edited by
      #3

      Maybe you didn't see this in my posting:

      bq. In the QProcess documentation, I read that arguments with spaces are wrapped in quotes, so I tried not including the quotes – didn’t work. The doc. for the 2nd version of the ‘QProcess::start()’ method, which doesn’t have a separate QStringList for arguments, mentions that quotes ‘need to be both escaped and quoted’, with \” becoming \”\”\”. Tried this too, no luck.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Smar
        wrote on last edited by
        #4

        [quote author="livingWithQt" date="1280938914"]Maybe you didn't see this in my posting:

        bq. In the QProcess documentation, I read that arguments with spaces are wrapped in quotes, so I tried not including the quotes – didn’t work. The doc. for the 2nd version of the ‘QProcess::start()’ method, which doesn’t have a separate QStringList for arguments, mentions that quotes ‘need to be both escaped and quoted’, with \” becoming \”\”\”. Tried this too, no luck. [/quote]

        I'm not master with Qt, so please be patient with my newbie'ish helping... I said that because I've recently had similar problems with Windows and after all I were able to somehow get it work after messing up with arguments until they started to work...

        What kind of errors you get? Some kind of simple test about this would help me, but can you get arguments you are passing to octave out as seen by octave?

        1 Reply Last reply
        0
        • L Offline
          L Offline
          livingWithQt
          wrote on last edited by
          #5

          bq. I’m not master with Qt, so please be patient with my newbie’ish helping…

          I apologize if my reply sounded rude or something.

          bq. but can you get arguments you are passing to octave out as seen by octave?

          Are you talking about taking a look at the string I'm finally passing to the Octave executable? Yes, I already looked into this, but there's no way in Qt (that I know of, I'm a newbie too... :)) to see what the QProcess object is actually doing with the 2 args (QString - exec. path; QStringList - arguments). Do you know of a way to do this?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Smar
            wrote on last edited by
            #6

            No problems, I just have too sharp tongue sometimes...

            I don't know what this "octave" is and how it expects to get the parameters herself, so I'd suggest to make a simple test program which you can use to test how the arguments behaves. If it works as expected with this dummy program, it is octave that interprets the arguments wrong.

            1 Reply Last reply
            0
            • ? This user is from outside of this forum
              ? This user is from outside of this forum
              Guest
              wrote on last edited by
              #7

              spaces are easily handled, I just tried this with a jpg file in "Program Files" directory of windows:
              @
              QString cmd("mspaint");
              QStringList args;
              args << "c:\Program Files\tanu.jpg";
              pr->start(cmd, args);
              @

              1 Reply Last reply
              1
              • ? This user is from outside of this forum
                ? This user is from outside of this forum
                Guest
                wrote on last edited by
                #8

                Just tried with double quotes with the below snip, and even that works!

                @
                QString cmd("firefox");
                QStringList args;
                args << "http://www.google.co.in/search?q="qt+jambi"";
                pr->start(cmd, args);
                @

                In my firefox, I had google with qt jambi search done and URL in the browser reads:
                http://www.google.co.in/search?q="qt+jambi"

                1 Reply Last reply
                0
                • ? This user is from outside of this forum
                  ? This user is from outside of this forum
                  Guest
                  wrote on last edited by
                  #9

                  to your comment:

                  [ P.S. The ‘forward slash’es I put in several places have been removed in the preview. I don’t know if they will be missing from the final post. ]

                  You can actually preview and see how it looks in the final post ... or use @code here @ ... and everything will be preserved :)

                  1 Reply Last reply
                  0
                  • ? This user is from outside of this forum
                    ? This user is from outside of this forum
                    Guest
                    wrote on last edited by
                    #10

                    sorry .. use the @ symbol before and after ur code

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      Smar
                      wrote on last edited by
                      #11

                      Offtopic, but... You can also edit your posts, instead of making double posts.

                      And about code tags and quote tags and others: there are buttons for them at panel at top of this textarea...

                      bq. Just tried with double quotes with the below snip, and even that works!

                      Naturally, as it takes a QStringList as argument, it can handle all escaping by itself. It would be different story if you'd need to use single string for arguments and program; then you'd need to do the escaping yourself, because the framework can't read your thoughts.

                      When thinking this, always using QStringList for arguments saves time and avoid idiomatic bugs... When you forget one or two quotes from somewhere.

                      1 Reply Last reply
                      0
                      • ? This user is from outside of this forum
                        ? This user is from outside of this forum
                        Guest
                        wrote on last edited by
                        #12

                        Thanks Smar, new to the forum and didn't realize I could edit a post :)

                        1 Reply Last reply
                        0
                        • JeroentjehomeJ Offline
                          JeroentjehomeJ Offline
                          Jeroentjehome
                          wrote on last edited by
                          #13

                          @
                          QStringList qslArguments;

                          qslArguments.append("127.0.0.1");
                          qslArguments.append(qsStrapId);
                          
                          qpProcess.start("BMI_REMOTE", qslArguments);
                          

                          @
                          This just works fine. Don't bother about quotes etc. Qt will do it for you if I'm not mistaken, dependent on the OS you are running. Windows normally has a / as a argument separator, Linux uses a space. Qt will fix it for you. It is also possible to handle it yourself using the overloaded function of process::start (). Here you can give just 1 Qstring with the program name and all parameters added yourself. You can easily debug it yourself, but that would make it a bit less OS independent.
                          good luck!

                          Greetz, Jeroen

                          1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            goetz
                            wrote on last edited by
                            #14

                            Please don't necropost to threads that ended over a year ago. Thanks.

                            http://www.catb.org/~esr/faqs/smart-questions.html

                            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