Attempting to read stdout from spawned QProcess

251 views Asked by At

I've written a Qt application to create a UI to a backend Linux console application. Now, I want the console output and the standard error to be displayed in a window in my application.

I've tried the following code :

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 !
}

When I execute the application, the error that I get is :

Object::connect: No such signal
QProcess::console_backend>readyReadStandardOutput() in
../projekt_directory/mainwindow.cpp:239 
Object::connect:  (receiver name: 'MainWindow')

Am I understanding signals-and-slots wrong ? Why is it "No such signal" ? Is the entire approach wrong ?

1

There are 1 answers

0
Vikram On BEST ANSWER

Issue is in statement

QObject::connect(console_backend, SIGNAL(console_backend
                 ->readyReadStandardOutput()),
                 this, SLOT(this->receiveConsoleBackendOutput()));

It should be

QObject::connect(console_backend, SIGNAL(readyReadStandardOutput()),
                 this, SLOT(receiveConsoleBackendOutput()));