I need to develop a GUI program which will be run some external bash script. This script are working about 30-40 minutes and I want to see system output in my application in real time.
How can I provide this? Should I use QTextStream?
Please give me some examples.
If you launch the script via QProcess, you can get the output by connecting to the readyRead signal. Then it's just a matter of calling any of the read functions to get the data and then displaying it on any type of widget you want, such as a QTextEdit which has an append function for adding text.
Something like this: -
// Assuming QTextEdit textEdit has been created and this is in a class
// with a slot called updateText()
QProcess* proc = new QProcess;
connect(proc, SIGNAL(readyRead()), this, SLOT(updateText()));
proc->start("pathToScript");
...
// updateText in a class that stored a pointer to the QProcess, proc
void ClassName::updateText()
{
QString appendText(proc->readAll());
textEdit.append(appendText);
}
Now, every time the script produces text, your updateText function is called and you are adding it to the QTextEdit object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With