Results 1 to 8 of 8

Thread: QProcess -> link output of 3rd party app back to my app

  1. #1
    Join Date
    Dec 2007
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QProcess -> link output of 3rd party app back to my app

    Hi,

    at the moment i am using the following construction to launch a 3rd party app from my QT-based UI (developed on and for windows).

    The cmd construction looks like this:
    Qt Code:
    1. QProcess::startDetached("C2oooProgConsole.exe -s -d="+selectedDspType +" -p="+ selectedInterface +" -h="+ windowsFileName +" -c");
    To copy to clipboard, switch view to plain text mode 

    So basically the 3rd party app is a commandline based application with some custom parms, which are defined in my UI.

    Unfortunaly this output does launch itself in a DOS-Commandbox (cmd.exe) and closes itself after finishing. So i cant even read the output, as the window is already closed again.

    As i cant find a parameter for this 3rd party app to let it pause after having finished i was thinking about linking the output directly into my app bck again, so that every single line which happens on the cmd-window is returned to my application UI. In best case i would just link it back to a QTextEdit which i am using right now as log-text-field.

    That is the theoretical description....but is that somehow possible ? and if yes what should i search for in the AT doc's ? any suggestion / ideas ?

    Best regards
    ape

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QProcess -> link output of 3rd party app back to my app

    Try
    Qt Code:
    1. cmd.exe /k <command> <params..>
    To copy to clipboard, switch view to plain text mode 
    Oh, and I believe you should use a QStringList for the arguments, see QProcess::startDetached() docs.
    J-P Nurmi

  3. #3
    Join Date
    Dec 2007
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QProcess -> link output of 3rd party app back to my app

    Hi jpn,

    my basic construction works but yeah i have realized the QStringList point yesterday already.
    Was just wondering if i really need to change my construction...as it was working ok already.

    Regarding the pausing option:
    your cmd.exe /k idea works great.

    Guess i have to add a case-selection for old -windows systems where cmd was called command....but that should be easy right now.

    Like always: big thanks to you JPN...you are a big help.
    Best regards
    ape

  4. #4
    Join Date
    Dec 2007
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QProcess -> link output of 3rd party app back to my app

    Just realized that this construction does have a major problem.

    QProcess construction:
    Qt Code:
    1. QProcess::startDetached("cmd.exe /k C2oooProgConsole.exe -s -d="+selectedDspType +" -p="+ selectedInterface +" -h="+ windowsFileName +" -c");
    To copy to clipboard, switch view to plain text mode 

    Problem:
    If the variable "windowsFileName" does contains Spaces my QProcess construction does not work.

    small example:
    a) windowsFileName
    C:\testfolder\subfolder\myfile.xy
    does work

    b) if windowsFileName =
    C:\test folder\subfolder\myfile.xy
    does NOT work and ends up ion the following error in cmd.exe:

    File not found: C:\test

    I guess thats the issue cause cmd just cuts the command/path of my file at the moment it reaches the Space. So am i correct, that i need to change my QProcess-construction or better the windowsfileName section to be sure that spaces does not matter anymore ?

    But how would i do that ?
    Usualy you would just add "" around the path but what is the solution in the contruction above ?

    The only theoretical idea i have right now is adding " infront and behind the variable before evne using it. i.e. using prepend and append, but that does not work and i am not sure what is the best method to modify strings AND if this idea is solved better with another method
    Last edited by ape; 12th March 2008 at 12:39.

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QProcess -> link output of 3rd party app back to my app

    You should pass all the arguments in a QStringList.
    J-P Nurmi

  6. #6
    Join Date
    Dec 2007
    Posts
    33
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QProcess -> link output of 3rd party app back to my app

    Hi jpn,

    ok i guess this time i really should follow your hint.

    I got it working in the meantime using this construction:

    Qt Code:
    1. windowsFileName.prepend('"');
    2. windowsFileName.append('"');
    To copy to clipboard, switch view to plain text mode 

    but thats pretty dirty style.


    Gonna test this a bit more and then try to implement your idea.

    Like always: big thanks for your fast & good help.

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QProcess -> link output of 3rd party app back to my app

    In fact, it would have been enough to actually read QProcess::startDetached() docs:
    On Windows, arguments that contain spaces are wrapped in quotes.
    Qt Code:
    1. QStringList arguments;
    2. arguments << "/k" << "C2oooProgConsole.exe" << "-s" << ...;
    3. QProcess::startDetached("cmd.exe", arguments);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  8. #8
    Join Date
    Apr 2009
    Posts
    41
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QProcess -> link output of 3rd party app back to my app

    it is popup output along with cmd prompt. how to disappear that cmd prompt

Similar Threads

  1. QProcess and capturing output
    By Aragorn in forum Qt Programming
    Replies: 7
    Last Post: 3rd May 2007, 16:57

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.