title: Qt: Signal and slots and Q_OBJECT
body: <p>I have written a program in Qt, it works fine, but clicking on push buttons does not work.
  When I use Q_OBJECT just after the class declaration, it gives me compilation errors.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    #include &lt;QApplication&gt;
      #include &lt;QPushButton&gt;
      #include &lt;QLabel&gt;
      #include &lt;QWidget&gt;
  
      class Communicate : public QWidget
      {
       // Q_OBJECT
  
        public:
          Communicate(QWidget *parent = 0);
  
        private slots:
          void OnPlus();
          void OnMinus();
  
        private:
          QLabel *label;
  
      };
  
      Communicate::Communicate(QWidget *parent)
          : QWidget(parent)
      {
        QPushButton *plus = new QPushButton("+", this);
        plus-&gt;setGeometry(50, 40, 75, 30);
  
        QPushButton *minus = new QPushButton("-", this);
        minus-&gt;setGeometry(50, 100, 75, 30);
  
        label = new QLabel("0", this);
        label-&gt;setGeometry(190, 80, 20, 30);
  
        connect(plus, SIGNAL(clicked()), this, SLOT(OnPlus()));
        connect(minus, SIGNAL(clicked()), this, SLOT(OnMinus()));
      }
  
      void Communicate::OnPlus()
      {
        int val = label-&gt;text().toInt();
        val++;
        label-&gt;setText(QString::number(val));
      }
  
      void Communicate::OnMinus()
      {
        int val = label-&gt;text().toInt();
        val--;
        label-&gt;setText(QString::number(val));
      }
  
      int main(int argc, char *argv[])
      {
        QApplication app(argc, argv);
  
        Communicate window;
  
        window.setWindowTitle("Communicate");
        window.show();
  
        return app.exec();
      }
  </code></pre>