How to define an OnClick event handler for a button from within Qt Creator?
In the designer,
- add Push Button to the form
- right click the Push Button
- select "Go to slot..."
- select "clicked()" signal
- done
The terms are different from .NET, so in this case we are talking about signals and slots, and the signal emitted when QPushButton is clicked is called clicked()
instead of OnClick
.
Reading the Qt's documentation about signals and slots is recommended.
In header file:
private slots:
void exit_app();
in xyz.cpp:
connect(ui.button_name, SIGNAL(clicked()), this, SLOT(exit_app()));
define the exit_app() func that SLOT calls.
void QtTest2::exit_app()
{
QApplication::exit();
}