我正在使用Qt来实现允许为嵌入式系统开发的接口。
我面临一个问题:为了将程序闪存到嵌入式系统中,我使用QProcess,以便使用命令“ make”和“ make flash”。为了没有任何问题,该程序可以成功编译。
但是当我尝试对“ make flash”执行相同的操作时,由于控制台正在等待用户输入,他必须按下嵌入式系统上的按钮。
但是QProcess仅在脚本完成后才返回标准输出,因此我没有消息“按下按钮”。
所以我的问题是:我怎么知道QProcess需要用户输入的时间?还是如果不可能,如何使用Qt动态打开控制台并启动命令?
我尝试了这里所说的:https://www.qtcentre.org/threads/47538-QProcess-read-from-stdout-lively
这是我的代码:
compilator->start("make flash"); compilator->waitForFinished(); QByteArray errors = compilator->readAllStandardError(); QString stringError(errors); QByteArray message = compilator->readAll(); QString stringMessage(message); m_logForm->setText("Project path : " + pathProject + "\n" + "Flash finished with exit code " + QString::number(compilator->exitCode()) + "\n" + stringError + "\n" + stringMessage + "\n");
其中m_logFrom是用于在我的界面中显示控制台报告的类
[编辑]我尝试了弗拉基米尔的话。不幸的是,我没有我的资料,所以我无法对其进行测试,但是为了完成测试,我已经完成了此脚本(test.bat):
set /p answer=Do you want to create it now (Y/N)?
这是我的新代码:
QProcess *compilator = new QProcess(this); connect(compilator, &QProcess::readyReadStandardOutput, [compilator, this](){ QString output =compilator->readAll(); qDebug() << "output: "<< output; m_logForm->setText("Flash finished with exit code " + QString::number(compilator->exitCode()) + "\n" + output + "\n"); }); connect(compilator, &QProcess::readyReadStandardError, [compilator, this](){ QString err = compilator->readAllStandardError(); qDebug() << "error: "<<err; m_logForm->setText("Flash finished with exit code " + QString::number(compilator->exitCode()) + "\n" + err + "\n"); }); m_logForm->setText("Flashing to serial port "+m_Serial + "\n"); compilator->setWorkingDirectory(pathProject); compilator->start("test.bat"); }
但是它什么也没做
我正在使用Qt来实现允许为嵌入式系统开发的接口。我遇到了一个问题:为了将程序闪存到嵌入式系统中,我使用了QProcess,以便使用...
我的test.bat