PDA

View Full Version : QProcess Problem: Program doesnt start



musaulker
29th March 2007, 23:43
Hello,

I want to start a process from my software. Here is the code that I used:

bool MainForm::ProcessStart()
{
try
{
QProcess *programProcess = new QProcess();
programProcess>setWorkingDirectory("c:\\");

QStringList arguments;
arguments << "-foo " << bar;

programProcess>start("c:\\foobar.exe");
return true;
}
catch (int e)
{
return false;
}
}

void MainForm::ProgramStart()
{
if (!ProcessStart())
{
QMessageBox::critical(this, QString::fromUtf8("Process foo cannot started!"),
QString::fromUtf8(
"<p>Foobar.exe cannot opened</p>"));
}
}

But the process didnt started. Whats the problem? Where's my wrong?

jacek
30th March 2007, 00:24
QProcess *programProcess = new QProcess();
Better store that pointer in a member variable, so that you can free it later, otherwise you'll get a memory leak.


arguments << "-foo " << bar;
It should be "-foo" not "-foo ". Also you don't use those arguments anywhere.


programProcess>start("c:\\foobar.exe");
Does it start if you enter:
cd c:\
C:\foobar.exe in cmd.exe?

Does programProcess emit error() signal?


catch (int e)
{
return false;
}
I wonder what is going to throw that exception. Especially that it's an integer. Are you sure that this is correct?

musaulker
30th March 2007, 00:45
Better store that pointer in a member variable, so that you can free it later, otherwise you'll get a memory leak.

Yes, I'll change it.. Thanks


It should be "-foo" not "-foo ". Also you don't use those arguments anywhere.

But what if I want to put a space between more than one arguments? (like: foobar.exe -foo bar foofoo)



Does it start if you enter: in cmd.exe?

The problem is probably because of escape characters. Sorry about the path. The true path is like:

C:\Documents and Settings\Administrator\foobar.exe
So I must escape them. Anyway it doesnt worked as I escaped. My firewall (Zone-Alarm) gives a security alert saying:

MySoftware.exe is trying to launch C:\Documents and Settings\Administrator\foobar.exe, or use another program to gain access to privileged resources. Allow or Deny
I selected Allow but nothing happens. foobar.exe didn't open. I also disable the firewall and try again, nothing changed. Not whats the problem? What do you think?


Does programProcess emit error() signal?
the error says: QProcess::FailedToStart. From the documentation this means:

The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program.
But I know that program exists there, and I can run and use it normally. And also there musnt be a permission problem, I'm logged in as an administrator.


I wonder what is going to throw that exception. Especially that it's an integer. Are you sure that this is correct?
Amm :) In Visual Studio when a write try and press twice Tab button it opens template of try like this:

try
{
}
catch (CException* e)
{

}
but it gives a compiler error with this code. I've just changed it to int e, it worked :D I have a C# background but I dont know if this is working proberly or not. Maybe a bad coding. Dont know..
Is there a try/catch mechanism in QT library?

jacek
30th March 2007, 01:12
But what if I want to put a space between more than one arguments? (like: foobar.exe -foo bar foofoo)
You don't have to add spaces, because you pass parameters as a list.

parameters << "-foo" << "bar" << "foofoo";
Spaces are necessary only when you pass program name and parameters as a single string (for example to QProcess::startDetached()).



The problem is probably because of escape characters. Sorry about the path. The true path is like:
C:\Documents and Settings\Administrator\foobar.exe
You have used the two-parameter version of QProcess::start(), so Qt probably understood it as run program "C:\Documents" with parameters "and" and "Settings\Administrator\foobar.exe".

Try:
programProcess->start( "c:\\...\\foobar.exe", QStringList() );
// or if you want to add some parameters:
programProcess->start( "c:\\...\\foobar.exe", arguments );
or wrap that path in quotes:
programProcess->start( "\"c:\\...\\foobar.exe\"" );


but I dont know if this is working proberly or not.
It's very unlikely that something is going to throw an integer at you. Better remove both try and catch clauses.


Is there a try/catch mechanism in QT library?
Exceptions are part of C++ language, but Qt itself doesn't throw any exceptions.

lodhi.pr
30th April 2020, 18:19
HI i am also getting problem in starting the this is a simple QCreater GUI in which i want to start communication using Qprocess between two applications , i have tried many approaches but stuck at this point.


I have tried this method please help me if anyone found the solution to this

process = new QProcess();
process->setProcessChannelMode(QProcess::SeparateChannels);
process->start("./fifo");


if (!process->waitForStarted(100))
qDebug() << " Unable to startn process ::" << process->error() <<" Error msg" << process->errorString();


the Error i am getting here is : Unable to startn process :: QProcess::ProcessError(FailedToStart) Error msg "execvp: No such file or directory"


Please help !!

d_stranz
1st May 2020, 00:07
process->start("./fifo");

Do you actually have a file with execute permissions in your current working directory? Do you know what QtCreator thinks your working directory is? And does it agree with your idea?

Try replacing "." with the full path to your file and see if that works. And if it does, add a call to QDir::currentPath() so you can understand what QtCreator is thinking.