Results 1 to 7 of 7

Thread: QProcess error Using Arguments Qt 4.5

  1. #1
    Join Date
    Apr 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QProcess error Using Arguments Qt 4.5

    Hi All,

    My Problem is Using QProcess Class, I have a CLI application that works without arguments but if I pass some Arguments the process not run. Maybe I'm doing something wrong . This is a Code sample.

    Qt Code:
    1. QObject *parent;
    2. QProcess *nAp = new QProcess(parent);
    3.  
    4. //Path to the Application
    5. QString appPath = "/home/username/ConsoleApp ";
    6. QStringList arguments;
    7. arguments << "one";
    8. arguments << "two";
    9.  
    10. nAp->start( appPath, arguments );
    11. if(!nAp->waitForStarted(-1)) {
    12. qDebug() << "Ap has not started";
    To copy to clipboard, switch view to plain text mode 

    Thanks for the Help.

  2. #2
    Join Date
    Apr 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess error Using Arguments Qt 4.5

    I fix the problem myself the error was the space at the end of the Application Path.

  3. #3
    Join Date
    Apr 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: QProcess error Using Arguments Qt 4.5

    I have a similar problem, but it's not caused by a trailing space.

    This works:

    Qt Code:
    1. proc = new QProcess( parent );
    2. proc->start( "/home/user/path/to/prog/myprogram.exe -a -b -c" );
    To copy to clipboard, switch view to plain text mode 
    This doesn't work:
    Qt Code:
    1. proc = new QProcess( parent );
    2. proc->setWorkingDirectory( "/home/user/path/to/prog" );
    3. proc->start( "myprogram.exe -a -b -c" );
    To copy to clipboard, switch view to plain text mode 
    Adding a trailing '/' to the path in setWorkingDirectory makes no difference.

    The weirdest thing is, if I change "myprogram.exe" to "ls", for instance, then "ls" works and returns the contents of /home/user/path/to/prog

    What am I missing ?

  4. #4
    Join Date
    May 2009
    Posts
    61
    Thanks
    5
    Thanked 6 Times in 6 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess error Using Arguments Qt 4.5

    Very strange - I have the opposite: I cannot call command line tools, but only graphical programs (other thread).

    Does startDetached help? What about
    Qt Code:
    1. proc->start("myprogram", QStringList() << "-a -b")
    To copy to clipboard, switch view to plain text mode 
    ?

  5. #5
    Join Date
    Apr 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess error Using Arguments Qt 4.5

    Console vs Gui should make no difference (or, maybe you're creating the QProcess from inside a Widget ?) I call start() directly from main, then pass the QProcess handle to my MainWindow so that my widgets can reference it.

    In my case, I don't want to detach, since I need continuous communication between the QProcess and my app.

    The argument list is not a problem in my case. All of these work equally:
    Qt Code:
    1. proc->start("/path/to/myprogram.exe", QStringList() << "-a" << "-b")
    2. proc->start("/path/to/myprogram.exe", QStringList() << "-a -b")
    3. proc->start("/path/to/myprogram.exe -a -b")
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    May 2009
    Posts
    61
    Thanks
    5
    Thanked 6 Times in 6 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProcess error Using Arguments Qt 4.5

    Console vs Gui - yes, in theory. On Mac, I cannot open a console at all. But anyway...

    So the only thing left: setWorkingDirectory hast nothing to do where QProcess searches your program. That would explain why ls is started - it is in your path. Your program to start is not.
    Qt Code:
    1. proc = new QProcess( parent );
    2. proc->setWorkingDirectory( "/home/user/path/to/prog" );
    3. proc->start( "/home/user/path/to/prog/myprogram.exe -a -b -c" );
    To copy to clipboard, switch view to plain text mode 
    should do the job

  7. #7
    Join Date
    Apr 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess error Using Arguments Qt 4.5

    Well that makes sense I had thought setWorkingDirectory() would actually do a "cd" to this path before launching the process, which is not exactly the same thing...

    Thanks for the heads-up.

Similar Threads

  1. Replies: 3
    Last Post: 25th February 2009, 17:55
  2. Detect First QProcess finished in a group and kill other
    By Davidaino in forum Qt Programming
    Replies: 3
    Last Post: 11th July 2008, 13:53
  3. QProcess and none-string arguments
    By Raistlin in forum Qt Programming
    Replies: 8
    Last Post: 12th March 2008, 16:28
  4. Replies: 6
    Last Post: 21st September 2007, 14:51
  5. QProcess / system call not working under linux. Why?
    By johnny_sparx in forum Qt Programming
    Replies: 12
    Last Post: 11th March 2006, 01:32

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.