讀取使用readyReadStandardOutput輸出我使用Qt和我無法得到使用readyReadStandardOutput一個exe文件的輸出。不能在Qt的
這是我的代碼。
mainwindow.cpp
void MainWindow::on_pushButton_24_clicked()
{
myprocess = new QProcess(this);
myprocess->start("files\\helloworld.exe");
connect(myprocess, SIGNAL(readyReadStandardOutput()), this, SLOT(outlog()));
}
void MainWindow::outlog()
{
QString abc;
abc = myprocess->readAllStandardOutput();
emit outlogtext(abc);
ui->lineEdit_4->setText(abc);
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtGui>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
QProcess *myprocess;
signals:
void outlogtext(QString ver);
private slots:
void outlog();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
的將HelloWorld.exe的只是提供一個輸出 「Hello World」 的,但我不能看到它的文本編輯,我的代碼有什麼問題?我對Qt非常陌生。謝謝
你確定outlog()是插槽,而不僅僅是一個函數嗎? – Blood 2012-08-12 09:29:54
我想是的,我在第一篇文章中也添加了mainwindow.h。請看一看。 – 2012-08-12 09:41:08
您應該追加文本,而不是替換它,因爲輸出可能會出現在多個塊中,甚至可能會發出額外的readyRead以指示管道關閉。 – 2012-08-12 10:00:16