我有一個類View
合併我的QGraphicsView
但我有麻煩繼承它。我的代碼如下:Qt QGraphicsView事件
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);
};
我已經實現paintEvent
只是一個快速cout
在game
。當我編譯,一切編譯好的,但是當我跑,我不斷收到一個消息,說一個純虛函數被調用:
libc++abi.dylib: pure virtual method called
Abort trap: 6
我View
構造是這樣的:
View::View(QGraphicsScene * _scene) : QGraphicsView(_scene) {...
任何幫助不勝感激。
嘗試在您的基類中移除「paintEvent」的純虛擬(= 0)。由於它是從QT內部調用我認爲,這將是問題。 – AquilaRapax
當您獲得純虛擬通話時,您能否顯示通話堆棧? – Paul
我最終不得不爲基類中的paint事件實現一個空的函數。感謝您的快速解決方案 – JonMorehouse