尝试从生成的 QProcess 中读取标准输出
Attempting to read stdout from spawned QProcess
我编写了一个 Qt 应用程序来创建一个 UI 到后端 Linux 控制台应用程序。现在,我希望控制台输出和标准错误显示在我的应用程序的 window 中。
我试过以下代码:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QProcess *console_backend = new QProcess(this);
QString file = "/path/to/console_executable";
console_backend->start(file);
console_backend->setReadChannel(QProcess::StandardOutput);
QObject::connect(console_backend, SIGNAL(console_backend
->readyReadStandardOutput()),
this, SLOT(this->receiveConsoleBackendOutput()));
}
void MainWindow::receiveConsoleBackendOutput()
{
//..celebrate !
}
当我执行应用程序时,我得到的错误是:
Object::connect: No such signal
QProcess::console_backend>readyReadStandardOutput() in
../projekt_directory/mainwindow.cpp:239
Object::connect: (receiver name: 'MainWindow')
我对信号槽的理解有误吗?为什么是 "No such signal" ?
整个方法是错误的吗?
问题在声明中
QObject::connect(console_backend, SIGNAL(console_backend
->readyReadStandardOutput()),
this, SLOT(this->receiveConsoleBackendOutput()));
应该是
QObject::connect(console_backend, SIGNAL(readyReadStandardOutput()),
this, SLOT(receiveConsoleBackendOutput()));
我编写了一个 Qt 应用程序来创建一个 UI 到后端 Linux 控制台应用程序。现在,我希望控制台输出和标准错误显示在我的应用程序的 window 中。
我试过以下代码:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QProcess *console_backend = new QProcess(this);
QString file = "/path/to/console_executable";
console_backend->start(file);
console_backend->setReadChannel(QProcess::StandardOutput);
QObject::connect(console_backend, SIGNAL(console_backend
->readyReadStandardOutput()),
this, SLOT(this->receiveConsoleBackendOutput()));
}
void MainWindow::receiveConsoleBackendOutput()
{
//..celebrate !
}
当我执行应用程序时,我得到的错误是:
Object::connect: No such signal
QProcess::console_backend>readyReadStandardOutput() in
../projekt_directory/mainwindow.cpp:239
Object::connect: (receiver name: 'MainWindow')
我对信号槽的理解有误吗?为什么是 "No such signal" ? 整个方法是错误的吗?
问题在声明中
QObject::connect(console_backend, SIGNAL(console_backend
->readyReadStandardOutput()),
this, SLOT(this->receiveConsoleBackendOutput()));
应该是
QObject::connect(console_backend, SIGNAL(readyReadStandardOutput()),
this, SLOT(receiveConsoleBackendOutput()));