Results 1 to 5 of 5

Thread: QProcess - quotes and spaces in parameters under Linux

  1. #1
    Join Date
    Nov 2010
    Posts
    9
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Question QProcess - quotes and spaces in parameters under Linux

    Hello,
    I'm trying to use ImageMagick with QProcess under Linux. The arguments are quite complicated, the whole command needed is for example:
    Qt Code:
    1. convert /tmp/temporaryPicture20.png -matte -virtual-pixel transparent -define distort:viewport=1105x3241+4572829+2684426 -distort Perspective '592,154 4572830,2684542 1408,54 4573934,2684426 654,2432 4572942,2687666 ' +repage /tmp/temporaryPicture20_out.png
    To copy to clipboard, switch view to plain text mode 
    Documentation suggests that such parameters may be tricky in Windows and Unix is piece of cake, but still I don't get how to use QProcess. What i tried was:
    a) puttin the whole command in QString and passing it to QProcess::start(QString) (without separate arguments)
    b)
    Qt Code:
    1. QString command = "convert";
    2. args
    3. <<"/tmp/mapin.png"
    4. <<"-matte"
    5. <<"-virtual-pixel"
    6. <<"transparent"
    7. <<"-define"
    8. <<"distort:viewport=1105x3241+4572829+2684426"
    9. <<"-distort"
    10. <<"Perspective"
    11. <<"'592,154 4572830,2684542 1408,54 4573934,2684426 654,2432 4572942,2687666'"
    12. <<"+repage"
    13. <<"/tmp/mapout.png";
    14. iProcess->start(command,args);
    To copy to clipboard, switch view to plain text mode 
    and some variations of b) (escaping spaces "\ ", escaping single quotes "\'", using double quotes instead of single ones and some other. In all cases finished(int,status) signal is emited with arguments 0,1 (1 is bad, right?), the output image is produced but not distorted according to -distort Perspective '(...)' , so (probably) some arguments are passed correctly, but this one is ignored as faulty.

    How do i pass it correctly?
    Last edited by mateuszzz88; 3rd July 2011 at 22:55. Reason: spelling corrections pointed out by SixDegrees

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QProcess - quotes and spaces in parameters under Linux

    The numeric argument to 'perspective' isn't properly quoted.

    I'd suggest using the variant that takes a single string argument. Then, you can print out the argument and examine it for errors, or simply try pasting it onto the command line to see if it runs as expected.

    Note, too, that you may not be able to assume a 'standard' environment when invoking processes this way. You may have to call setEnvironment to ensure that ImageMagick is able to find what it needs in order to run.
    Last edited by SixDegrees; 3rd July 2011 at 22:25.

  3. #3
    Join Date
    Jan 2009
    Location
    The Netherlands and Spain
    Posts
    150
    Thanks
    6
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QProcess - quotes and spaces in parameters under Linux

    Maybe you should split the numbers that are separated by spaces into separate args.

  4. #4
    Join Date
    Nov 2010
    Posts
    9
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Lightbulb Re: QProcess - quotes and spaces in parameters under Linux

    Quote Originally Posted by SixDegrees View Post
    The numeric argument to 'perspective' isn't properly quoted.

    I'd suggest using the variant that takes a single string argument.
    Sorry, that's true, but it's typo in forum only (wouldn't even compile, wolud it? )
    I tried single string argument - marked as a) :-) Printed command works, QProcess doesn't.

    Quote Originally Posted by boudie View Post
    Maybe you should split the numbers that are separated by spaces into separate args.
    The numbers are all one argument wrapped by single quotes.


    Added after 5 minutes:


    Well, boudie's post made me thinking about some more radical experiments. Turns out that not only in windows (as I undersood the documentation) arguments with spaces are quoted. Proper way is:
    Qt Code:
    1. args
    2. <<"/tmp/mapin.png"
    3. <<"-matte"
    4. <<"-virtual-pixel"
    5. <<"transparent"
    6. <<"-define"
    7. <<"distort:viewport=1105x3241+4572829+2684426"
    8. <<"-distort"
    9. <<"Perspective"
    10. <<"592,154 4572830,2684542 1408,54 4573934,2684426 654,2432 4572942,2687666"
    11. <<"+repage"
    12. <<"/tmp/mapout.png";
    13. iProcess->start("convert",args);
    To copy to clipboard, switch view to plain text mode 
    There's no additional quotes for numbers list even though quotes are necessary when issuing command by hand.
    Thank you for your time, sorry for not thinking it out earlier.
    Last edited by mateuszzz88; 3rd July 2011 at 23:00.

  5. The following user says thank you to mateuszzz88 for this useful post:

    abbaasi69 (30th August 2020)

  6. #5
    Join Date
    Jul 2020
    Posts
    6
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QProcess - quotes and spaces in parameters under Linux

    well done. I had the same problem with running the following command:
    transformMesh -scale '(1, 2, 1)'
    which I should use QProcess as follows:
    Qt Code:
    1. myProc.start("transformMesh" , QStringList() << "-scale" << "(1,2,1)" ); // without single quotes
    To copy to clipboard, switch view to plain text mode 
    Last edited by abbaasi69; 30th August 2020 at 20:45. Reason: spelling corrections

Similar Threads

  1. Replies: 8
    Last Post: 28th January 2015, 10:45
  2. qmake LIBS missing quotes
    By redoctober0 in forum General Programming
    Replies: 1
    Last Post: 12th January 2011, 17:05
  3. QSqlQuery and single quotes using bindValue
    By Luc4 in forum Qt Programming
    Replies: 4
    Last Post: 27th September 2010, 00:34
  4. Replies: 5
    Last Post: 4th February 2010, 00:50
  5. Replies: 1
    Last Post: 7th April 2008, 16:12

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.