title: Qt: Signals and slots Error: undefined reference to `vtable for
body: <p>Following example from this link: <a href="http://developer.kde.org/documentation/books/kde-2.0-development/ch03lev1sec3.html">http://developer.kde.org/documentation/books/kde-2.0-development/ch03lev1sec3.html</a></p>
  
  <pre><code>#include &lt;QObject&gt;
  #include &lt;QPushButton&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  class MyWindow : public QWidget
  {
      Q_OBJECT  // Enable slots and signals
      public:
          MyWindow();
      private slots:
          void slotButton1();
          void slotButton2();
          void slotButtons();
      private:
          QPushButton *button1;
          QPushButton *button2;
  };
  
  MyWindow :: MyWindow() : QWidget()
  {
      // Create button1 and connect button1-&gt;clicked() to this-&gt;slotButton1()
      button1 = new QPushButton("Button1", this);
      button1-&gt;setGeometry(10,10,100,40);
      button1-&gt;show();
      connect(button1, SIGNAL(clicked()), this, SLOT(slotButton1()));
  
      // Create button2 and connect button2-&gt;clicked() to this-&gt;slotButton2()
      button2 = new QPushButton("Button2", this);
      button2-&gt;setGeometry(110,10,100,40);
      button2-&gt;show();
      connect(button2, SIGNAL(clicked()), this, SLOT(slotButton2()));
  
      // When any button is clicked, call this-&gt;slotButtons()
      connect(button1, SIGNAL(clicked()), this, SLOT(slotButtons()));
      connect(button2, SIGNAL(clicked()), this, SLOT(slotButtons()));
  }
  
  // This slot is called when button1 is clicked.
  void MyWindow::slotButton1()
  {
      cout &lt;&lt; "Button1 was clicked" &lt;&lt; endl;
  }
  
  // This slot is called when button2 is clicked
  void MyWindow::slotButton2()
  {
      cout &lt;&lt; "Button2 was clicked" &lt;&lt; endl;
  }
  
  // This slot is called when any of the buttons were clicked
  void MyWindow::slotButtons()
  {
      cout &lt;&lt; "A button was clicked" &lt;&lt; endl;
  }
  
  int main ()
  {
      MyWindow a;
  }
  </code></pre>
  
  <p>results in:</p>
  
  <pre><code>    [13:14:34 Mon May 02] ~/junkPrograms/src/nonsense  $make
  g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/opt/qtsdk-2010.05/qt/mkspecs/linux-g++-64 -I. -I/opt/qtsdk-2010.05/qt/include/QtCore -I/opt/qtsdk-2010.05/qt/include/QtGui -I/opt/qtsdk-2010.05/qt/include -I. -I. -o signalsSlots.o signalsSlots.cpp
  g++ -m64 -Wl,-O1 -Wl,-rpath,/opt/qtsdk-2010.05/qt/lib -o nonsense signalsSlots.o    -L/opt/qtsdk-2010.05/qt/lib -lQtGui -L/opt/qtsdk-2010.05/qt/lib -L/usr/X11R6/lib64 -lQtCore -lpthread
  signalsSlots.o: In function `MyWindow::MyWindow()':
  signalsSlots.cpp:(.text+0x1a2): undefined reference to `vtable for MyWindow'
  signalsSlots.cpp:(.text+0x1aa): undefined reference to `vtable for MyWindow'
  signalsSlots.o: In function `MyWindow::MyWindow()':
  signalsSlots.cpp:(.text+0x3e2): undefined reference to `vtable for MyWindow'
  signalsSlots.cpp:(.text+0x3ea): undefined reference to `vtable for MyWindow'
  signalsSlots.o: In function `main':
  signalsSlots.cpp:(.text+0x614): undefined reference to `vtable for MyWindow'
  signalsSlots.o:signalsSlots.cpp:(.text+0x61d): more undefined references to `vtable for MyWindow' follow
  collect2: ld returned 1 exit status
  make: *** [nonsense] Error 1
  </code></pre>
  
  <p>vtable is for virtual functions, AFAIK, what's the reason of error here?</p>