我有一个合并了我的QGraphicsView的类View,但是我在继承它时遇到了麻烦。我的代码如下:
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;而Game继承自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);
};我已经在game中用一个快速的cout实现了paintEvent。当我编译时,一切都可以正常编译,但当我运行时,我总是收到一条消息,说调用了一个纯虚函数:
libc++abi.dylib: pure virtual method called
Abort trap: 6我的View构造函数如下所示:
View::View(QGraphicsScene * _scene) : QGraphicsView(_scene) {...任何帮助都将不胜感激。
发布于 2012-10-17 18:57:42
我获得了paintEvent函数来编译和打开我的应用程序。但由于某些原因,每当我试图在我的场景上绘制时,它都不起作用。
但是,如果我去掉paintEvent函数,它就能正常工作。对于paintEvent为什么会破坏这一点,有什么建议吗?
在我的主文件中:
QGraphicsEllipseItem * item = new QGraphicsEllipseItem(0, scene);
item->setRect(50.0, 50.0, 100.0, 100.0);
view->setRenderHints(QPainter::Antialiasing);
view->show();如果我去掉了虚拟的paintEvent函数,这是可行的,但是包含它会打破画出的圆吗?
https://stackoverflow.com/questions/12931016
复制相似问题