我写了一个helloworld,希望通过QProcess运行,并且读取输出,但是怎样都读取不到
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QString my_process_2 = "C:/Users/lin/Desktop/qt_1/t1.exe";
process = new QProcess();
qDebug()<<my_process_2;
QStringList argument;
process->start(my_process_2);
if (!process->waitForStarted())
{
qDebug() << "启动失败";
}
connect(process,SIGNAL(readyRead()),this,SLOT(Fctn_get_info()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::Fctn_get_info()
{
qDebug()<<"start";
QString s = tr("");
s+= process->readAll();
qDebug()<<s;
return;
}
求大神解答
Signals:
void readyReadStandardOutput()
QByteArray QProcess::readAllStandardOutput()
Regardless of the current read channel, this function returns all data available from the standard output of the process as a QByteArray.
你可以用这个信号,readyReadStandardOutput()
我就这么用的,应该可以的,你的t1.exe程序是否正常启动了,t1.exe是否有输出,或者你的信号链接时t1.exe已经输出过了。
QString cmd = QString("lftp -c 'open -e \"lcd d:/data; mirror -veR ./ \" admin:admin@localhost'");
_process.start(cmd, QProcess::ReadWrite);
我试过了很多方法,但是读取的都不完全,我循环输出hellow world 但是只能读取到一部分,如果循环次数少了,就什么也读取不到
这个可以用
https://zhuanlan.zhihu.com/p/337850909
System.out,print("你要输出的内容");