Results 1 to 7 of 7

Thread: QProcess issue with GPG under Windows

  1. #1
    Join Date
    Jul 2011
    Posts
    42
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QProcess issue with GPG under Windows

    Hey there, im having a few issues trying to use QProcess to create a sub-process that runs GPG on the background.

    I had previously implemented the functionality with windows specific methods, but since we are porting everything to Linux and Mac i thought it would be nice to let QProcess handle everything.

    The problem is that the arguments that QProcess is building are not compatible with the type or argument GPG expects (GPG is pretty sensitive).
    My code look like this:
    Qt Code:
    1. QList<GPGKey> GPGKeyManagement::getKeys(GPGParameter *param)
    2. {
    3. QList<GPGKey> list;
    4.  
    5. args << "--homedir . --list-keys";
    6. //args << "--homedir . ";
    7. //args << " --list-keys ";
    8.  
    9. if (param)
    10. {
    11. // add the information specified in param to the args
    12. }
    13.  
    14. QProcess gpg;
    15. gpg.setProcessChannelMode(QProcess::MergedChannels);
    16. gpg.start("gpg.exe", args);
    17.  
    18. if (!gpg.waitForFinished())
    19. qDebug() << "Error: " << gpg.errorString();
    20. else
    21. {
    22. QString response(gpg.readAll());
    23. qDebug() << response;
    24. list = parseKeysFromOutput(response);
    25. }
    26.  
    27. return list;
    28. }
    To copy to clipboard, switch view to plain text mode 

    i also tried this, with no luck:
    Qt Code:
    1. gpg.start("gpg.exe --homedir . --list-keys", args); //args empty
    2. or
    3. args << "gpg.exe --homedir . --list-keys";
    4. gpg.start("", args);
    To copy to clipboard, switch view to plain text mode 

    When Qt builds the command line it does 'gpg "--homedir . --list-keys" ' and so GPG complains about the double quotes added.
    Was anyone able to call gpg from a QProcess in Windows?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QProcess issue with GPG under Windows

    What happens if you do:
    Qt Code:
    1. args << "--homedir"<<"."<<"--list-keys";
    2. gpg.start("gpg.exe", args);
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jul 2011
    Posts
    42
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess issue with GPG under Windows

    Thanks for the replay, im afraid it was no good either. I also tried

    Qt Code:
    1. args << "--homedir . " << " --list-keys";
    To copy to clipboard, switch view to plain text mode 

    but it didnt work. I kinda imagine why qt is doing such thing, but maybe it would be nice to be able to customize the way we want to build the command line arguments to avoid this problems with super sensitive software like Gpg.
    Im wondering if this issue will happen in linux and mac as well, because if it happens, then im gonna have to forget about QProcess and do it my self for each platform. What do u think?


    Thanks!

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QProcess issue with GPG under Windows

    Something is not right.
    The arguments QPrcoess generates should not have quotes (" ") in them.
    Argument in general don't need (" ") , unless it an argument value which is a string.
    But I can't see what you are doing wrong in what you posted.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Jul 2011
    Posts
    42
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess issue with GPG under Windows

    i see, well i dont know what else to do. Im gonna try the test case on Mac to see what happens.

    I'll let you know how it goes!

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QProcess issue with GPG under Windows

    What Daniel suggests in post #2 should work fine. Please make sure you followed his advice accurately. Each argument should be its own string in the string list.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jul 2011
    Posts
    42
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess issue with GPG under Windows

    I've tried that, and still not working. Here's what the command argument that QProcess builds, looks like in the debuger:

    args "gpg.exe " --homedir " " . " " --list-keys""

    If i build a single argument, the result is the same, it adds quotes to the single argument, and the variable in the debugger looks like:

    args "gpg.exe "--homedir . --list-keys"""

    So its clear that QProcess is adding surrounding quotes to the command line arguments. The same is happening on Mac.



    Added after 6 minutes:


    We have found a solution for this issue on windows, using setNativeArguments(). The code looks like this:
    Qt Code:
    1. gpg.setProcessChannelMode(QProcess::MergedChannels);
    2. gpg.setNativeArguments("--homedir . --list-keys");
    3. gpg.start("gpg");
    To copy to clipboard, switch view to plain text mode 

    This works perfectly fine. The problem is that this method is only avaliable on Windows, so the same problem is happening on Mac and i can use that solution.

    -------------------------------------------------------------------------------------
    We solved the issue, i looked at the qt_create_commandline() static function to find where or why the quotes were added. According to the algorithm, is the argument has a ' ' then it is wrapped in quotes. Since i was adding a space, every argument ended up wrapped.
    The solution now looks like: (and it works both on windows and mac)
    Qt Code:
    1. args << "--homedir" << "." << "--list-keys"; //do not add any space on each argument!
    2.  
    3. QProcess gpg;
    4. gpg.setProcessChannelMode(QProcess::MergedChannels);
    5. gpg.start("gpg", args);
    To copy to clipboard, switch view to plain text mode 

    Thanks for your help!
    Last edited by superpacko; 7th September 2011 at 21:48.

Similar Threads

  1. Replies: 7
    Last Post: 15th November 2010, 10:00
  2. QProcess issue
    By bunjee in forum Qt Programming
    Replies: 5
    Last Post: 21st December 2009, 08:40
  3. Replies: 3
    Last Post: 25th February 2009, 17:55
  4. need help for QProcess under windows
    By patcito in forum Qt Programming
    Replies: 4
    Last Post: 26th May 2006, 20:54
  5. Qprocess never end in MS windows
    By antonio.r.tome in forum Qt Programming
    Replies: 12
    Last Post: 23rd February 2006, 13:35

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.