title: How to add clicked signal and slot to custom button in qt
body: <p>I have a Box class that inherits from <code>QPushButton</code>. I want to have a onClick event on the button by using connect (SIGNAL and SLOT) and call a custom function <code>onClick()</code> declared in box.h</p>
  <pre class="lang-cpp prettyprint-override"><code>box.h
  #ifndef BOX_H
  #define BOX_H
  
  #include &lt;QPushButton&gt;
  
  class Box : public QPushButton {
  public:
      Box(const QString&amp; text, QWidget* parent = nullptr);
      void onClick();
  };
  
  #endif // BOX_H
  
  </code></pre>
  <pre class="lang-cpp prettyprint-override"><code>//box.cpp
  #include &quot;box.h&quot;
  
  Box::Box(const QString&amp; text, QWidget* parent)
      : QPushButton(text, parent)
  {
      connect(this, SIGNAL(clicked()), SLOT(this-&gt;onClick()));
  }
  
  void Box::onClick()
  {
      this-&gt;setText(&quot;Something&quot;);
  }
  </code></pre>