GUIman
8th March 2011, 22:27
I don't understand this error:
Undefined reference to 'vtable for Spaceship' Spaceship.cpp 9
Undefined reference to 'vtable for Spaceship' Spaceship.cpp 9
collect2: ld returned 1 exit status
spaceship.h:
#ifndef SPACESHIP_H
#define SPACESHIP_H
#include <QGraphicsItem>
#include <QObject>
class Spaceship : public QGraphicsItem
{
public:
Spaceship();
QRectF boundingRect() const;
QPainterPath shape() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
protected:
void advance(int step);
private:
qreal angle;
qreal speed;
QColor color;
};
#endif // SPACESHIP_H
spaceship.cpp:
#include "spaceship.h"
#include <QGraphicsScene>
#include <QPainter>
#include <QStyleOption>
#include <QObject>
#include <math.h>
Spaceship::Spaceship()
{
setRotation(0);
}
void Spaceship::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
//Draw the Spaceship
painter->setBrush(Qt::black);
painter->drawRect(10, 10, 20, 20);
}
void Spaceship::advance(int step)
{
if (!step)
return;
angle = 0;
speed += 1;
setPos(mapToParent(0, -(3 + speed) *3));
}
main.cpp:
#include "spaceship.h"
#include <QtGui>
#include <math.h>
#include <QObject>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QGraphicsScene scene;
scene.setSceneRect(-300, -300, 600, 600);
scene.setItemIndexMethod(QGraphicsScene::NoIndex);
Spaceship *ship = new Spaceship;
ship->setPos(0,0);
scene.addItem(ship);
QGraphicsView view(&scene);
view.setRenderHint(QPainter::Antialiasing);
view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsVie w, "Spaceship"));
view.resize(400, 300);
view.show();
QTimer timer;
QObject::connect(&timer, SIGNAL(timeout()),&scene, SLOT(advance()));
timer.start(1000 / 33);
return app.exec();
}
I was trying to modify the colliding mice example to just show a block move upward.
Thank you very much
Undefined reference to 'vtable for Spaceship' Spaceship.cpp 9
Undefined reference to 'vtable for Spaceship' Spaceship.cpp 9
collect2: ld returned 1 exit status
spaceship.h:
#ifndef SPACESHIP_H
#define SPACESHIP_H
#include <QGraphicsItem>
#include <QObject>
class Spaceship : public QGraphicsItem
{
public:
Spaceship();
QRectF boundingRect() const;
QPainterPath shape() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
protected:
void advance(int step);
private:
qreal angle;
qreal speed;
QColor color;
};
#endif // SPACESHIP_H
spaceship.cpp:
#include "spaceship.h"
#include <QGraphicsScene>
#include <QPainter>
#include <QStyleOption>
#include <QObject>
#include <math.h>
Spaceship::Spaceship()
{
setRotation(0);
}
void Spaceship::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
//Draw the Spaceship
painter->setBrush(Qt::black);
painter->drawRect(10, 10, 20, 20);
}
void Spaceship::advance(int step)
{
if (!step)
return;
angle = 0;
speed += 1;
setPos(mapToParent(0, -(3 + speed) *3));
}
main.cpp:
#include "spaceship.h"
#include <QtGui>
#include <math.h>
#include <QObject>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QGraphicsScene scene;
scene.setSceneRect(-300, -300, 600, 600);
scene.setItemIndexMethod(QGraphicsScene::NoIndex);
Spaceship *ship = new Spaceship;
ship->setPos(0,0);
scene.addItem(ship);
QGraphicsView view(&scene);
view.setRenderHint(QPainter::Antialiasing);
view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsVie w, "Spaceship"));
view.resize(400, 300);
view.show();
QTimer timer;
QObject::connect(&timer, SIGNAL(timeout()),&scene, SLOT(advance()));
timer.start(1000 / 33);
return app.exec();
}
I was trying to modify the colliding mice example to just show a block move upward.
Thank you very much