i have a problem with a small program (I am a beginner with c++ and qt). On button press it starts a cli application with qprocess and the output should be displayed in a text field as soon as the cli app writes it to stdout or stderr.
i read that its a good idea to use signals and slots for this but it isnt working.
the compiler throws an error that in my slot getOutput() the "process" object isn't declared (C2065)
here is the code.
processgui.cpp:
#include "processgui.h"
#include "ui_processgui.h"
#include <QProcess>
processGui::processGui(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::processGui)
{
ui->setupUi(this);
}
processGui::~processGui()
{
delete ui;
}
void processGui::on_startProcess_clicked() {
QProcess *process = new QProcess(this);
QString program = "tracert";
QString arguments = "";
process->setReadChannelMode(QProcess::MergedChannels);
process->start(program, QStringList() << arguments);
process->waitForStarted();
QObject::connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(getOutput()));
}
void processGui::getOutput() {
QByteArray strdata = process->readAllStandardOutput();
ui->textLog->append(strdata);
}
processgui.h :
#ifndef PROCESSGUI_H
#define PROCESSGUI_H
#include <QMainWindow>
namespace Ui {
class processGui;
}
class processGui : public QMainWindow
{
Q_OBJECT
public:
explicit processGui(QWidget *parent = 0);
~processGui();
private slots:
void on_startProcess_clicked();
void getOutput();
private:
Ui::processGui *ui;
};
#endif // PROCESSGUI_H
thanks in advance