Error reading readAll StandardOutput()
-
void MainWindow::on_pushButton_2_clicked(){ QProcess process; QStringList command; command << "flashrom -p serprog:dev=/dev/ttyACM0:115200 -r /home/ti/Downloads/uno.rom "; process.start("/bin/sh", QStringList()<< "-c" << command); process.waitForFinished(); QString word = process.readAllStandardOutput(); ui->textEdit->setText(word);
}
@e-ferro
if ( true == process.waitForFinished() ) { QString word = process.readAllStandardOutput(); ui->textEdit->setText(word); } or if ( true == process.waitForFinished(6000 ) ) { /*add 6s whatever you need */ QString word = process.readAllStandardOutput(); ui->textEdit->setText(word); }
Christian is right. Run the script directly. I did not pay attention to it. set all of them "-p" "serprog:dev=/dev/ttyACM0:115200" "-r" "/home/ti/Downloads/uno.rom" to string list as arguments
-
I really wonder why everyone thinks a shell is needed just to execute a program. Is this somewhere in the Qt docs or so?
Don't use /bin/sh and execute flashrom directly.
Sorry sir, I'm new to qt world and I'm trying to learn to make a project with Flashrom + Arduino. Everywhere I look for how to read the Terminal, I only find it that way. If I can help, I'm willing to learn.
-
@e-ferro said in Error reading readAll StandardOutput():
QProcess process;
create a process pointer inside MainWindow
m_process = new QProcess;
delete it in the destructor -
Using command:
process.startCommand("flashrom -p serprog:dev=/dev/ttyACM0:115200 -r /home/ti/Downloads/uno.rom ");
removing /bin/sh
the message stays
QProcess: Destroyed while process ("flashrom") is still running.
If I start with startDetached
The entire log of the operation appears in the Application Output but is not read by readAllStandardOutput()
-
@e-ferro said in Error reading readAll StandardOutput():
QProcess process;
create a process pointer inside MainWindow
m_process = new QProcess;
delete it in the destructor -
Using command:
process.startCommand("flashrom -p serprog:dev=/dev/ttyACM0:115200 -r /home/ti/Downloads/uno.rom ");
removing /bin/sh
the message stays
QProcess: Destroyed while process ("flashrom") is still running.
If I start with startDetached
The entire log of the operation appears in the Application Output but is not read by readAllStandardOutput()
@e-ferro
class MainWindow : public QMainWindow { ... your stuff... private: QProcess * m_process{}; }; void MainWindow::on_pushButton_2_clicked(){ if ( nullptr == _process ) { m_process = new QProcess; } m_process->start(...); if ( true == process->waitForFinished() ) { QString word = m_process->readAllStandardOutput(); ui->textEdit->setText(word); } }
-
void MainWindow::on_pushButton_2_clicked(){ QProcess process; QStringList command; command << "flashrom -p serprog:dev=/dev/ttyACM0:115200 -r /home/ti/Downloads/uno.rom "; process.start("/bin/sh", QStringList()<< "-c" << command); process.waitForFinished(); QString word = process.readAllStandardOutput(); ui->textEdit->setText(word);
}
@e-ferro said in Error reading readAll StandardOutput():
process.waitForFinished();
Let's establish what this is returning:
bool result = process.waitForFinished(); qDebug() << "waitForFinished:" << result;
Because it sounds like that is returning false, then the
QProcess process
would go out of scope while the process is still running and hence the error message.One question: if you go into a terminal, type your
flashrom -p ...
command, I can see it runs up a UI. If you run this from a shell in a terminal, does the command complete immediately and show the next line's shell prompt while the UI is still being shown? If so that means in any case you cannot wait forflashrom
to exit to indicate it has finished doing whatever reading/writing it does. -
@e-ferro
class MainWindow : public QMainWindow { ... your stuff... private: QProcess * m_process{}; }; void MainWindow::on_pushButton_2_clicked(){ if ( nullptr == _process ) { m_process = new QProcess; } m_process->start(...); if ( true == process->waitForFinished() ) { QString word = m_process->readAllStandardOutput(); ui->textEdit->setText(word); } }
-
There is no need for a thread. QProcess is asynchronous already so if the operation takes a long time, just exploit properly this asynchronous nature.
-
There is no need for a thread. QProcess is asynchronous already so if the operation takes a long time, just exploit properly this asynchronous nature.
-
@e-ferro
I asked for output of the result ofprocess.waitForFinished()
, which you do not show.The answer looks quite simple anyway. You have never said how long it takes for the flashrom to run, till you see the
QProcess: Destroyed while process ("/bin/sh") is still running
message. If you had said "flashrom takes quite some time to run, and I see that message after 30 seconds", we would have known immediately.bool QProcess::waitForFinished(int msecs = 30000) waits by default for 30 seconds for the sub-process to finish. If it has not finished by then it returns false (operation timed out) and then your code continues executing. When your code exits the
on_pushButton_2_clicked()
slot theQProcess process
variable goes out of scope, and you will get that warning message because the sub-process is still running.Assuming you want your Qt program to simply do nothing and wait until the flashrom application exits, you should call:
process.waitForFinished(-1);
Now you will get its complete output and not get that warning message.
Be aware that the user will not be able to do anything at all in your Qt application while it is waiting like this. I am guessing this is fine by you. If you do want the user be able to do other things in your app while flashrom is running, you would have to change to using signals and slots.
-
Now it works with the command
process.waitForFinished(-1);
The difference is that the log message only appears after the end of the process and the program is frozen, but it works perfectly. But now I put a message for the user to wait. Thanks a lot guys for the help!!
-
There is no need for a thread. QProcess is asynchronous already so if the operation takes a long time, just exploit properly this asynchronous nature.
Then as suggested before, you should take advantage of the asynchronous nature of QProcess so your users won't be in front of a frozen UI maybe a disabled one but not frozen.