Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to redirect system output to my gui app (qt, linux)?

Tags:

linux

output

qt

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.

like image 456
wlredeye Avatar asked Dec 30 '25 17:12

wlredeye


1 Answers

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.

like image 148
TheDarkKnight Avatar answered Jan 02 '26 10:01

TheDarkKnight



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!