Hi guys,
I just started study about QT, and doing an example i had some doubts.
My code is something like that:
main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <iostream>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
void MainWindow::readyReadStdout(){
cout << "Reading!! " << endl;
}
void MainWindow::on_pushButton_released(){
proc = new QProcess(this); // memory allocation from heap, created with parent
connect( proc, SIGNAL(readyReadStandardOutput()),this, SLOT(readyReadStdout()) );
proc->start("ls");
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
#include <qprocess.h>
namespace Ui
{
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
private:
QProcess *proc; // pointer definition
Ui::MainWindow *ui;
private slots:
void on_pushButton_released();
void readyReadStdout();
};
#endif // MAINWINDOW_H
So, i have one button , and when the user press the button i'd like to start a process, in that case the command ls, and get the result.
With this code what happening is, when i pressed the button, the process ls starts but the signal readyReadStandardOutput() comes only when i click to finish Mainwindow, i mean when i click in the exit button.
How can i do to get the signal in the same time that it happened?
Thanks !!