How to connect signals from within the GUI/form creator to code.

  • I've been experimenting with QT in the QTCreator tool kit, and I can't work out how to connect a button::clicked() signal to a custon written slot.

    I have my class DockWidget which I created using the "QT Designer form class" wizard. And I have a simple dock widget with a button on it. I then added a public slot for the click button signal (to DockWidget) (and wrote the function in the respective cpp file):

    @public slots:
    void onClickButton();@

    Then I go to the form layout designer and under "Signals and slots editor" I select the pushButton object as the sender, the clicked() signal and the DockWidget object as the reciever, however my slot isn't in drop down menu for slots.

    I'm definitely doing something wrong but at the moment I've been going by trial and error because I can't find any documentation on writing code along side using the form designer. Am I doing something very patently wrong? Could I have some documentation on connecting the objects I've created in the form designer to actual code?

    Thanks in advanced.

  • Oh, that's what ui is for...

    connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(on_pushButton_clicked()));@

    All of the objects from that form are available there. Stupid me.

  • If you use prefix and suffix in your slots, e.g. "on_widgetName_clicked()". Qt will connect signals and slots automatically.

Log in to reply