Hi.
I try to compile the example of the QObject derived class "Counter" on
http://doc.trolltech.com/4.1/signalsandslots.html
but I only get this error:

Qt Code:
  1. g++ -c -pipe -O2 -march=athlon-xp -pipe -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/doc/qt-4.1.0-r2/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o q.o q.cpp
  2. g++ -o snor q.o -L/usr/lib/qt4 -lQtGui -L/usr/lib/mysql -L/usr/lib -L/usr/lib/qt4 -laudio -lXt -lpng -lSM -lICE -lXi -lXrender -lXrandr -lXcursor -lfreetype -lfontconfig -lXext -lX11 -lQtCore -lz -lm -ldl -lpthread
  3. q.o: In function `main':
  4. q.cpp:(.text+0x4b): undefined reference to `vtable for Counter'
  5. q.cpp:(.text+0x69): undefined reference to `vtable for Counter'
  6. q.cpp:(.text+0xbb): undefined reference to `vtable for Counter'
  7. q.cpp:(.text+0xcd): undefined reference to `vtable for Counter'
  8. q.cpp:(.text+0xe8): undefined reference to `vtable for Counter'
  9. q.o:q.cpp:(.text+0xf7): more undefined references to `vtable for Counter' follow
  10. q.o: In function `Counter::setValue(int)':
  11. q.cpp:(.text+0x16): undefined reference to `Counter::valueChanged(int)'
  12. collect2: ld returned 1 exit status
  13. make: *** [snor] Error 1
To copy to clipboard, switch view to plain text mode 

What's wrong?
Here is the code:

Qt Code:
  1. #include <QObject>
  2.  
  3. class Counter : public QObject
  4. {
  5. Q_OBJECT
  6. public:
  7. Counter() { m_value = 0; }
  8. int value() const { return m_value; }
  9. public slots:
  10. void setValue(int value);
  11. signals:
  12. void valueChanged(int newValue);
  13. private:
  14. int m_value;
  15. };
  16.  
  17.  
  18. void Counter::setValue(int value)
  19. {
  20. if (value != m_value) {
  21. m_value = value;
  22. emit valueChanged(value);
  23. }
  24. }
  25.  
  26.  
  27. int main()
  28. {
  29. Counter a, b;
  30. QObject::connect(&a, SIGNAL(valueChanged(int)),
  31. &b, SLOT(setValue(int)));
  32. a.setValue(12); // a.value() == 12, b.value() == 12
  33. b.setValue(48); // a.value() == 12, b.value() == 48
  34. }
To copy to clipboard, switch view to plain text mode