title: Qt connect function
body: <p>I'm trying to program a Qt GUI in C++. Here is the code: </p>
  
  <p>sample.h:</p>
  
  <pre><code>#ifndef SAMPLE_H
  #define SAMPLE_H
  
  #include &lt;QtGui/QApplication&gt;
  #include &lt;QtGui/QPushButton&gt;
  #include &lt;QtGui/QWidget&gt;
  #include &lt;QtGui/QGridLayout&gt;
  #include &lt;QtGui/QLineEdit&gt;
  #include &lt;qobject.h&gt;
  
  class Sample : public QObject
  {
      Q_OBJECT
  public:
      Sample();
  public slots:
      void buttonPressed();
  private:
      QWidget *widget;
      QGridLayout *layout;
      QLineEdit *le;
      QPushButton *button;
  };
  
  #endif // SAMPLE_H
  </code></pre>
  
  <p>sample.cpp:</p>
  
  <pre><code>#include "sample.h"
  
  Sample::Sample()
  {
      widget = new QWidget();
      widget-&gt;setWindowTitle("Sample");
      layout = new QGridLayout();
  
      le = new QLineEdit();
  
      button = new QPushButton();
      button-&gt;setText("Button");
  
      connect(button, SIGNAL(clicked()), this, SLOT(buttonPressed()));
      layout-&gt;addWidget(le, 0, 0);
      layout-&gt;addWidget(button, 1 , 0);
  
      widget-&gt;resize(300, 300);
      widget-&gt;setLayout(layout);
      widget-&gt;show();
  }
  
  void Sample::buttonPressed(){
      le-&gt;setText("pressed");
  }
  </code></pre>
  
  <p>I obtain this error when building: </p>
  
  <pre><code>error: undefined reference to `vtable for Sample'
  </code></pre>
  
  <p>I'm using QtCreator from official Qt webpage.</p>
  
  <p>Does anybody know what to do to make it work? Thank you very much for your responses :) </p>