Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define an OnClick event handler for a button from within Qt Creator?

People also ask

How do I create a Button click event?

Simply add the eventhandler to the button when creating it. button. Click += new EventHandler(this. button_Click); void button_Click(object sender, System.

How do you handle Button click events?

Onclick in XML layout When the user clicks a button, the Button object receives an on-click event. To make click event work add android:onClick attribute to the Button element in your XML layout. The value for this attribute must be the name of the method you want to call in response to a click event.

How do I know which Button is clicked QT?

At first, all buttons are hidden. In page load, I read data from database to show the text of function button; if the function button is not active then the button is also invisible. In that code, I save all active functions in a list and then get the list count.


In the designer,

  1. add Push Button to the form
  2. right click the Push Button
  3. select "Go to slot..."
  4. select "clicked()" signal
  5. 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();
}