Sending a signal to my mainwindow



  • hi to everyone
    i have a mainwindow and a qwidget. i create a qwidget class to in my mainwindow class
    now i want to when a button on qwidget clicked i send a signal to my mainwindow and my mainwindow do a slot i define
    how can i do it?
    can you give me an example?



  • Let your widget emit a signal when the button is pressed. Let then your main window connect to that signal.

    @CustomWidget::CustomWidget()
    {
    // ...
    connect(someButton, SIGNAL(clicked()), this, SIGNAL(somethingTriggered()));
    }

    MainWindow::MainWindow()
    {
    // ...
    connect(myCustomWidget, SIGNAL(somethingTriggered()), this, SLOT(doSomethingUseful()));
    }@



  • Please follow the "tutorial":http://developer.qt.nokia.com/wiki/Basic_Qt_Programming_Tutorial on the Wiki on this.



  • @MyMainWindow(){
    MyWidget * wdgt = new MyWidget(this);
    connect(wdgt, SIGNAL(mySignal()), this, SLOT(onComeSignal()));
    }

    class MyWidget : public QWidget{ Q_OBJECT
    public: MyWidget(QWidget * parent): QWidget(parent){
    QPushButton * btn = new QPushButton(this);
    connect(btn, SIGNAL(clicked (bool), this, SLOT(onClick(bool)));
    }
    private slots: onClick(bool){emit mySignal();}
    signals: void mySignal();
    }@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.