Qt : QProcess in a Loop
Qt : QProcess in a Loop
From my last post, I create a program how to use QProcess in our program. Now, I try to write a method how Qt : QProcess in a loop method. This problem show when I try to use QProcess in a loop. I have list of command line program (running from bash or konsole) and I want to running that all list command from Qt.
We can solve Qt : QProcess in loop problem with use void QProcess::finished ( int exitCode, QProcess::ExitStatus exitStatus ) [signal]. This signal is emitted when the process finishes. exitCode is the exit code of the process, and exitStatus is the exit status. After the process has finished. You can read the complete description from this function at Qt Documentation. This is my screenshot of simple program Qt : QProcess in a loop :
This is description from Qt : QProcess in a loop program above. From the left listbox, I have some of extension of file (*.so, *.a, etc). From this program, I use find command(linux find command) at location “/usr” with parameter :
find /usr -name extension_from_list_1_to_end -print
Output text from this program will show in textEdit (widget at right location). This is my void QProcess::finished function to solve Qt : QProcess in a loop problem :
//this function will executed at the end of every process void Qt_Loop_QProcess::finishedProcess ( int exitCode, QProcess::ExitStatus exitStatus ) { ui.textReport->append("complete"); //finishid process command if(idxProcess<nExtension) //run qprocess again until all extension finished { ui.listCommand->setCurrentRow(idxProcess); /* create QProcess object */ proc= new QProcess(); QString strCommand = setCommand(listExtension.at(idxProcess)); proc->start("/bin/bash", QStringList() << "-c" << strCommand); /* show output */ connect(proc, SIGNAL(readyReadStandardOutput()),this, SLOT(rightMessage()) ); connect(proc, SIGNAL(readyReadStandardError()), this, SLOT(wrongMessage()) ); connect(proc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(finishedProcess(int, QProcess::ExitStatus)) ); idxProcess++; } }
This Qt : QProcess in a loop program will process every extension at left location until all extension processed. You can get information processes that are running from selected item at listwidget (left widget position). This is a output from Qt : QProcess in a loop program when we press QProcess Loop button :
You can download the complete Qt : QProcess in a loop source code at here.
Hi,
I am not able to download the source code for this as it is opening some fly ad website while i click on “You can download all this code in this location.” so reply how can I download the same.
Hi Prashant, I have update the link. Please check that.
I came across your site wanting to learn more and you did not disappoint. Keep up the terrific work, and just so you know, I have bookmarked your page to stay in the loop of your future posts. Here is mine at 67U about Airport Transfer. Have a wonderful day!
Your posts in this blog really shine! Glad to gain some new insights, which I happen to also cover on my page. Feel free to visit my webpage QU9 about Thai-Massage and any tip from you will be much apreciated.