I have Embedded Qt applicaiton runing on my HMI screen.
I am trying to execute some commands to execute in cmd.
I am calling this c++ function simply from QML.
Everytime I call it it hangs on process.start().
Do anyone have any experience for such issue? please help.
I have ceated a simple function to print out date and it still hangs at process.start() regardless what cmd I execute.
cmd.sprintf("date +%%F' '%%X");
qDebug() << "cmd: " << cmd;
process.start("sh", QStringList()<<"-c"<<cmd);
process.waitForFinished(1000);
dtval = process.readAllStandardOutput();
process.close();
I am using Qt 5.9 on Ubuntu 18.04.6LTS platform.
2
Answers
What I found on my side is, the issue was debug mode. If I create release and press the run button (Ctlr + R) then it is absolutely fine (Not the debug button but Run button on QtCreator). Without any changes to my code. I have no idea what that would make the difference on application though.
I did some further troubleshooting, and I think I found a mistake in your start command. It should be:
Your mistake was your command
date
was joined to its arguments whereas it should have been separate.Since you were interested in QML, I mocked up the following C++ application where I invoked a similar command:
I also made the program listen and wait for either
onReadyReadStandardOutput
and/oronReadyReadStandardError
before callingprocess.readAllStandardOutput()
and/orprocess.readAllStandardError()
respectively.For convenience, I also mapped the
OpenMode
flags so that they can be used in QML.When you run the program there’s a "Go!" button in the footer. When you click on it, it runs the
process.start()
, and the output, be it either regular output or error gets displayed in theListView
above. When I run it, I see an output like this:qtquickcontrols2.conf:
And qml.qrc: