View Full Version : QProcess error Using Arguments Qt 4.5
xanders
13th April 2009, 04:17
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 :confused:. This is a Code sample.
QObject *parent;
QProcess *nAp = new QProcess(parent);
//Path to the Application
QString appPath = "/home/username/ConsoleApp ";
QStringList arguments;
arguments << "one";
arguments << "two";
nAp->start( appPath, arguments );
if(!nAp->waitForStarted(-1)) {
qDebug() << "Ap has not started";
Thanks for the Help.
xanders
14th April 2009, 18:30
I fix the problem myself the error was the space at the end of the Application Path.
magnosis
13th May 2009, 21:23
I have a similar problem, but it's not caused by a trailing space.
This works:
proc = new QProcess( parent );
proc->start( "/home/user/path/to/prog/myprogram.exe -a -b -c" );
This doesn't work:
proc = new QProcess( parent );
proc->setWorkingDirectory( "/home/user/path/to/prog" );
proc->start( "myprogram.exe -a -b -c" );
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 ?
Very strange - I have the opposite: I cannot call command line tools, but only graphical programs (other thread).
Does startDetached help? What about
proc->start("myprogram", QStringList() << "-a -b")?
magnosis
15th May 2009, 14:36
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:
proc->start("/path/to/myprogram.exe", QStringList() << "-a" << "-b")
proc->start("/path/to/myprogram.exe", QStringList() << "-a -b")
proc->start("/path/to/myprogram.exe -a -b")
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.
proc = new QProcess( parent );
proc->setWorkingDirectory( "/home/user/path/to/prog" );
proc->start( "/home/user/path/to/prog/myprogram.exe -a -b -c" );
should do the job
magnosis
15th May 2009, 15:56
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.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.