undefined reference to 'vtable ...'
I don't understand this error:
Code:
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:
Code:
#ifndef SPACESHIP_H
#define SPACESHIP_H
#include <QGraphicsItem>
#include <QObject>
{
public:
Spaceship();
protected:
void advance(int step);
private:
qreal angle;
qreal speed;
};
#endif // SPACESHIP_H
spaceship.cpp:
Code:
#include "spaceship.h"
#include <QGraphicsScene>
#include <QPainter>
#include <QStyleOption>
#include <QObject>
#include <math.h>
Spaceship::Spaceship()
{
setRotation(0);
}
{
//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:
Code:
#include "spaceship.h"
#include <QtGui>
#include <math.h>
#include <QObject>
int main(int argc, char **argv)
{
scene.setSceneRect(-300, -300, 600, 600);
Spaceship *ship = new Spaceship;
ship->setPos(0,0);
scene.addItem(ship);
view.
setRenderHint(QPainter::Antialiasing);
view.
setWindowTitle(QT_TRANSLATE_NOOP
(QGraphicsView,
"Spaceship"));
view.resize(400, 300);
view.show();
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
Re: undefined reference to 'vtable ...'
Have you defined this two member functions: QRectF boundingRect() const;, QPainterPath shape() const;?
Re: undefined reference to 'vtable ...'
Also, make sure you've added both the header and the implementation files to your .pro file.
Re: undefined reference to 'vtable ...'
try cleaning the project, remove debug/release folders, remove the makefiles and the .pro.user file, then open the project again and rebuild.
Re: undefined reference to 'vtable ...'
You need to provide the implementations for two virtual functions (one pure) you declare:
and the error goes away.
Re: undefined reference to 'vtable ...'
Thank you very much... I am an idiot