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

B Faley picture B Faley · Aug 4, 2013 · Viewed 51.3k times · Source

In visual studio, when designing a windows form, I can easily add an OnClick event handler for a button by double clicking on it. Is it possible to do the same in QtCreator? How should I handle the Click event of a button? Is manually writing the required code from scratch the only option?

Answer

user362638 picture user362638 · Aug 4, 2013

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.