I have a class View
that incorporates my QGraphicsView
but I am having trouble inheriting from it. My code is as follows:
class View: public QGraphicsView {//inherits qwidget -- so we can make it full screen there
Q_OBJECT
public:
View(QGraphicsScene * _scene);//this is responsible for setting up the screen and instantiating several elements
~View();
protected:
virtual void paintEvent(QPaintEvent * event) = 0;
And Game
inherits from View
:
#include "view.h" //this includes all of the functionality of the different elements
using namespace std;
class Game : public View {//inherit everything above and down into private functions
public:
Game(QGraphicsScene * _scene);
~Game();
protected:
void paintEvent(QPaintEvent * event);
};
I have implemented paintEvent
with just a quick cout
in game
. When I compile, everything compiles okay but when I run, I keep getting a message that says a pure virtual function was called:
libc++abi.dylib: pure virtual method called
Abort trap: 6
My View
constructor looks like this:
View::View(QGraphicsScene * _scene) : QGraphicsView(_scene) {...
Any help would be greatly appreciated.
I got the
paintEvent
function to compile and open my application. But for some reason, whenever I try to draw on my scene, it doesn't work.However, if I take out the
paintEvent
function, it works fine. Any suggestions as to why thepaintEvent
breaks this?in my main file:
This works if I get rid of the virtual
paintEvent
function, but including it will break the circle from drawing?