Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Read console output into a string
mandruk1331 last edited by mandruk1331
I have a gui applicatioon from which I start a console application, and I want to read the data from the console application into a QString variable, this is what I have for now. What is wrong with the code?
QProcess *process = new QProcess(this);
QString program = "nvidia-smi.exe";
@mandruk1331 What is wrong: you need to wait for the console application to output anything - if you read immediately after starting it there is simply nothing to read yet. You should connect a slot to http://doc.qt.io/qt-5/qprocess.html#readyReadStandardOutput signal (and one to http://doc.qt.io/qt-5/qprocess.html#readyReadStandardError) and call readAllStandardOutput() in that slot.
Usually there is no need to call close() if the console application terminates after it is done.
mandruk1331 last edited by
@jsulm Ok, I will give it a try