title: Error: symbol(s) not found for architecture x86_64, collect2: ld returned 1 exit status
body: <p>I have been struggling for a while with an issue on Qt.</p>
  
  <p>Here is my code:</p>
  
  <p>hexbutton.h:</p>
  
  <pre><code>#ifndef HEXBUTTON_H
  #define HEXBUTTON_H
  
  #include &lt;QPushButton&gt;
  #include &lt;QWidget&gt;
  #include &lt;QIcon&gt;
  
  class HexButton : public QPushButton
  {
      Q_OBJECT
  
  public:
      HexButton(QWidget *parent, QIcon &amp;icon, int i, int j);
  
  public slots:
      void changeIcon();
  };
  
  #endif // HEXBUTTON_H
  </code></pre>
  
  <p>Hexbutton.cpp:</p>
  
  <pre><code>#include "hexbutton.h"
  
  HexButton::HexButton(QWidget *parent, QIcon &amp;icon, int i , int j) : QPushButton(parent){
      //setFlat(true);
      setIcon(icon);
      setGeometry((i*40)+((j*40)/2), j*40, 40, 40);
  }
  
  void HexButton::changeIcon(){
          setIcon(QIcon("/Users/jonathanbibas/Documents/Workspace Qt/Test/hexagon.gif"));
  }
  </code></pre>
  
  <p>MyWindow.h:</p>
  
  <pre><code>#ifndef MYWINDOW_H
  #define MYWINDOW_H
  
  #include &lt;QApplication&gt;
  #include &lt;QWidget&gt;
  #include &lt;QPushButton&gt;
  #include &lt;QLCDNumber&gt;
  #include &lt;QSlider&gt;
  #include &lt;QProgressBar&gt;
  #include "hexbutton.h"
  
  
  
  class MyWindow : public QWidget
  {
  
  public:
      MyWindow();
      ~MyWindow();
  
  private:
      HexButton * myButtons[11][11];
  };
  
  
  
  #endif // MYWINDOW_H
  </code></pre>
  
  <p>MyWindow.cpp:</p>
  
  <pre><code>#include "MyWindow.h"
  #include &lt;QColor&gt;
  #include &lt;QIcon&gt;
  
  
  MyWindow::MyWindow() : QWidget() {
  
  
      setFixedSize(740, 440);
  
      QIcon icon = QIcon("/Users/jonathanbibas/Documents/Workspace Qt/Test/whitehexagon.png");
  
      for(int i =0 ; i &lt; 11 ; i ++){
          for(int j =0 ; j &lt; 11 ; j ++){
  
  
              myButtons[i][j] = new HexButton(this, icon, i, j);
  
              QObject::connect(myButtons[i][j], SIGNAL(clicked()), myButtons[i][j], SLOT(changeIcon()));
          }
      }
  }
  
  
  
  MyWindow::~MyWindow()
  {
      delete myButtons;
  
  }
  </code></pre>
  
  <p>And finally, Main.cpp:</p>
  
  <pre><code>#include &lt;QApplication&gt;
  #include "MyWindow.h"
  
  
  int main(int argc, char *argv[])
  {
      QApplication app(argc, argv);
  
          MyWindow fenetre;
          fenetre.show();
  
          return app.exec();
  }
  </code></pre>
  
  <p>Just in case, here is the Test.pro</p>
  
  <pre><code>SOURCES += \
      Main.cpp \
      MyWindow.cpp \
      hexbutton.cpp
  
  HEADERS += \
      MyWindow.h \
      hexbutton.h
  </code></pre>
  
  <p>And I get the 2 errors:</p>
  
  <p>1) symbol(s) not found for architecture x86_64</p>
  
  <p>2) collect2: ld returned 1 exit status</p>
  
  <p>It also says 121 times (11*11):</p>
  
  <p>Object::connect: No such slot QPushButton::changeIcon() in ../Test/MyWindow.cpp:19</p>
  
  <p>and on the compile output it says:</p>
  
  <pre><code>18:22:15: Running build steps for project Test...
  18:22:15: Configuration unchanged, skipping qmake step.
  18:22:15: Starting: "/usr/bin/make" -w
  make: Entering directory `/Users/jonathanbibas/Documents/Workspace Qt/Test-build-desktop-Desktop_Qt_4_8_0_for_GCC__Qt_SDK__Debug'
  g++ -c -pipe -g -gdwarf-2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -Wall -W -DQT_GUI_LIB -DQT_CORE_LIB -I../../../QtSDK/Desktop/Qt/4.8.0/gcc/mkspecs/macx-g++ -I../Test -I../../../QtSDK/Desktop/Qt/4.8.0/gcc/lib/QtCore.framework/Versions/4/Headers -I../../../QtSDK/Desktop/Qt/4.8.0/gcc/include/QtCore -I../../../QtSDK/Desktop/Qt/4.8.0/gcc/lib/QtGui.framework/Versions/4/Headers -I../../../QtSDK/Desktop/Qt/4.8.0/gcc/include/QtGui -I../../../QtSDK/Desktop/Qt/4.8.0/gcc/include -I. -I../Test -I. -F/Users/jonathanbibas/QtSDK/Desktop/Qt/4.8.0/gcc/lib -o hexbutton.o ../Test/hexbutton.cpp
  g++ -headerpad_max_install_names -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -o Test.app/Contents/MacOS/Test Main.o MyWindow.o hexbutton.o moc_MyWindow.o   -F/Users/jonathanbibas/QtSDK/Desktop/Qt/4.8.0/gcc/lib -L/Users/jonathanbibas/QtSDK/Desktop/Qt/4.8.0/gcc/lib -framework QtGui -framework QtCore 
  Undefined symbols for architecture x86_64:
    "vtable for HexButton", referenced from:
        HexButton::HexButton(QWidget*, QIcon&amp;, int, int)in hexbutton.o
        HexButton::HexButton(QWidget*, QIcon&amp;, int, int)in hexbutton.o
    NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  ld: symbol(s) not found for architecture x86_64
  collect2: ld returned 1 exit status
  make: *** [Test.app/Contents/MacOS/Test] Error 1
  make: Leaving directory `/Users/jonathanbibas/Documents/Workspace Qt/Test-build-desktop-Desktop_Qt_4_8_0_for_GCC__Qt_SDK__Debug'
  18:22:20: The process "/usr/bin/make" exited with code 2.
  Error while building project Test (target: Desktop)
  When executing build step 'Make'
  </code></pre>
  
  <p>Apparently the error comes from the Q_OBJECT (needed for the slots definition), but there is something wrong with my code, not with my compiler (because I have when slots are in MainWindow, it works fine).</p>
  
  <p>Thank you for your help!</p>