Unsolved Read console output into a string
-
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";
QStringList l;
l<<"-d";
process->start(program,l);
qDebug()<<process->state();
QString y(process->readAllStandardOutput());
process->close();
qDebug()<<y; -
@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. -
@jsulm Ok, I will give it a try