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 :confused:. This is a Code sample.
Code:
//Path to the Application
QString appPath
= "/home/username/ConsoleApp ";
arguments << "one";
arguments << "two";
nAp->start( appPath, arguments );
if(!nAp->waitForStarted(-1)) {
qDebug() << "Ap has not started";
Thanks for the Help.
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.
Re: QProcess error Using Arguments Qt 4.5
I have a similar problem, but it's not caused by a trailing space.
This works:
Code:
proc->start( "/home/user/path/to/prog/myprogram.exe -a -b -c" );
This doesn't work:
Code:
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 ?
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 ?
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:
Code:
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")
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.
Code:
proc->setWorkingDirectory( "/home/user/path/to/prog" );
proc->start( "/home/user/path/to/prog/myprogram.exe -a -b -c" );
should do the job
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.