I don't understand this error:
Qt Code:
  1. Undefined reference to 'vtable for Spaceship' Spaceship.cpp 9
  2. Undefined reference to 'vtable for Spaceship' Spaceship.cpp 9
  3. collect2: ld returned 1 exit status
To copy to clipboard, switch view to plain text mode 

spaceship.h:
Qt Code:
  1. #ifndef SPACESHIP_H
  2. #define SPACESHIP_H
  3.  
  4. #include <QGraphicsItem>
  5. #include <QObject>
  6.  
  7. class Spaceship : public QGraphicsItem
  8. {
  9.  
  10. public:
  11. Spaceship();
  12.  
  13. QRectF boundingRect() const;
  14. QPainterPath shape() const;
  15. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
  16.  
  17. protected:
  18. void advance(int step);
  19.  
  20. private:
  21. qreal angle;
  22. qreal speed;
  23. QColor color;
  24. };
  25.  
  26. #endif // SPACESHIP_H
To copy to clipboard, switch view to plain text mode 

spaceship.cpp:
Qt Code:
  1. #include "spaceship.h"
  2. #include <QGraphicsScene>
  3. #include <QPainter>
  4. #include <QStyleOption>
  5. #include <QObject>
  6. #include <math.h>
  7.  
  8. Spaceship::Spaceship()
  9. {
  10. setRotation(0);
  11. }
  12.  
  13. void Spaceship::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
  14. {
  15. //Draw the Spaceship
  16. painter->setBrush(Qt::black);
  17. painter->drawRect(10, 10, 20, 20);
  18. }
  19.  
  20. void Spaceship::advance(int step)
  21. {
  22. if (!step)
  23. return;
  24.  
  25. angle = 0;
  26. speed += 1;
  27. setPos(mapToParent(0, -(3 + speed) *3));
  28. }
To copy to clipboard, switch view to plain text mode 

main.cpp:
Qt Code:
  1. #include "spaceship.h"
  2. #include <QtGui>
  3. #include <math.h>
  4. #include <QObject>
  5.  
  6. int main(int argc, char **argv)
  7. {
  8. QApplication app(argc, argv);
  9. scene.setSceneRect(-300, -300, 600, 600);
  10. scene.setItemIndexMethod(QGraphicsScene::NoIndex);
  11.  
  12. Spaceship *ship = new Spaceship;
  13. ship->setPos(0,0);
  14. scene.addItem(ship);
  15.  
  16. QGraphicsView view(&scene);
  17. view.setRenderHint(QPainter::Antialiasing);
  18.  
  19. view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Spaceship"));
  20. view.resize(400, 300);
  21. view.show();
  22.  
  23. QTimer timer;
  24. QObject::connect(&timer, SIGNAL(timeout()),&scene, SLOT(advance()));
  25. timer.start(1000 / 33);
  26.  
  27. return app.exec();
  28. }
To copy to clipboard, switch view to plain text mode 

I was trying to modify the colliding mice example to just show a block move upward.

Thank you very much