PDA

View Full Version : system() function and QProgressBar



rajeshs
2nd June 2008, 08:15
Hi All,

I am calling c++ system() function to call run my script from command prompt like below,

system("ant -buildfile fileName"), i want to run progress bar while the system() function is

running , But if i call system() function one console is opening and running the script. How to

avoid console while running system() and how to use QProgressBar to display the status of

script while its running?

wysota
2nd June 2008, 08:18
Use QProcess instead.

rajeshs
2nd June 2008, 08:40
I tried QProcess and startDetached("cmd.exe","ant -buildFile FileName")

to start the process. Its working , but its running the script seperately, and next satement to

the QProcess is executing before the completion of the process started.

even i tried start instead of startDetached , start is not working for cmd.exe.

I tried to call waitForFinished() next to startDetached() method then also its executing next

statement before finishing the process, how to stop the execution until the process

completes.

My Code :




proc->startDetached("cmd.exe","ant -buildFile build.xml","D:/anttest");

proc->waitForFinished();

QMessageBox::information(this,"Success","ant Success","OK");

rajeshs
2nd June 2008, 09:02
I have gone through Qt Docs.

there its mentioned waitForFinished() should used for NON GUI. How to achieve the same in GUI
Apps.

Aceman2000
2nd June 2008, 09:09
Make a QEventLoop, connect the finished() signal of the QProcess to the quit() slot of the QEventloop, execute the QProcess, and immediately the QEventLoop. This technique will block until your process is really finished.

wysota
2nd June 2008, 10:16
As far as I know when you run an application as detatched, you won't receive a finished signal.

rajeshs
2nd June 2008, 11:23
I tried mapping finished() signal with qeventquit() slot, its stopping the execution but again its not starting even if the process finished.

jpn
2nd June 2008, 12:18
Notice that QProcess::startDetached() is a static method. Calling non-static methods have no effect on a detached process.

rajeshs
2nd June 2008, 12:19
how to achieve my requirement any suggestion Please ?

wysota
2nd June 2008, 16:25
Don't start the process as detached. If it doesn't work, it's because you made some mistake.

rajeshs
4th June 2008, 12:50
Sorry , I made mistake in start,

Previously I used

Wrong Code:




QProcess process = new QProcess(this)
process->start("cmd.exe /C ant -buildfile fileName");

to start the cmd process.

This is wrong,


Now i am using

Correct Code:




QProcess process = new QProcess(this)
process->start("cmd /C ant -buildfile fileName") ;

Now this is working.


Thank u for ur continuous help.