How to connect signals from within the GUI/form creator to code.
-
wrote on 3 Apr 2013, 16:06 last edited by
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.
-
wrote on 3 Apr 2013, 16:43 last edited by
Oh, that's what ui is for...
@ui->setupUi(this);
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(on_pushButton_clicked()));@All of the objects from that form are available there. Stupid me.
-
wrote on 3 Apr 2013, 18:50 last edited by
If you use prefix and suffix in your slots, e.g. "on_widgetName_clicked()". Qt will connect signals and slots automatically.
1/3