PDA

View Full Version : QProcess *proc at top of source (global?)



BrainFreeze
5th February 2008, 02:33
I have QProcess working fine, but I wanted to declare "QProcess *proc" at the top of the source (.cpp) file, so it's visible in more than one event handler. This causes make errors and/or segfaults. I've tried "proc->start(appString,argList);", and tried preceding with "*", "&". I also tried "." in place of "->". (Using Qt4, by the way). Does anyone know how to do this? Forgive me if this has been asked before, I wasn't sure what to search to find the answer.

BrainFreeze
5th February 2008, 02:47
I fixed it, never mind. At the top of the source file, I used "QProcess proc".
In the "connect" line I used:
"connect(&proc,SIGNAL(error(QProcess::ProcessError)),
this,SLOT(onProcessError(QProcess::ProcessError))) ;"
and another place I used "proc.setWorkingDirectory(wDir);" and
proc.start(appString,argList);
Now it builds, and no more segfault.

BrainFreeze
5th February 2008, 02:52
I TAKE THAT BACK - I'm getting a SEGFAULT, forgot to look in the console. Ok, so any ideas what I'm doing wrong?

BrainFreeze
5th February 2008, 04:47
Ok, I finally figured it out. I looked in the book "C++ GUI Programming With Qt4" and found out the easy (and correct) way. In the header file's "private" section, I placed "QProcess proc". In the source file, I connected proc to the proces error event handler like so:
connect(&proc,SIGNAL(error(QProcess::ProcessError)),this,SL OT(onProcessError(QProcess::ProcessError)));
To start the process I used this:
proc.start(appString,argList);
This line of code IS NOT NEEDED AT ALL:
QProcess *proc=new QProcess(this);
Now the process error handler works, too! It's way different that Qt3, takes me a while to learn.

ashukla
5th February 2008, 06:15
The best way is defining a such variabe or object in .h header files.