Qt Labs Forum » Graphics View

About signals :S

(3 posts)
  • Started 8 months ago by felipecpc
  • Latest reply from felipecpc

Tags:


  1. felipecpc
    felipecpc
    Member

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

    Posted: 8 months #
  2. MikkoL
    MikkoL
    Member

    Hi,

    Perhaps its a buffering issue for cout:

    
    cout << "Reading!! " << endl;
    cout.flush();
    
    Posted: 8 months #
  3. felipecpc
    felipecpc
    Member

    Hi ,
    you're right .... it works :)

    thanks !

    Posted: 8 months #

RSS feed for this topic

Reply

You must log in to post.



© 2008 Nokia Corporation and/or its subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide.
All other trademarks are property of their respective owners.