2012-10-17 3 views
0

나는 QGraphicsView을 통합하는 클래스 View을 가지고 있지만 문제를 상속 받고 있습니다. View에서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 상속 : 난 그냥 빠른 coutgame에서와 paintEvent을 구현 한

#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); 

}; 

다음과 같이 내 코드입니다. 내가 컴파일 할 때, 모든 것이 괜찮아 컴파일하지만 난 실행할 때, 나는 순수 가상 함수가 호출라는 메시지가 점점 계속 :

libc++abi.dylib: pure virtual method called 
Abort trap: 6 

View 생성자는 다음과 같습니다를 :

View::View(QGraphicsScene * _scene) : QGraphicsView(_scene) {... 

어떤 도움이 것 대단히 감사하겠습니다.

+3

기본 클래스에서'paintEvent'의 순수 가상 (= 0)을 제거해보십시오. QT 내에서 호출되기 때문에 이것이 문제가 될 것입니다. – AquilaRapax

+0

순수 가상 전화를받을 때 통화 스택을 표시 할 수 있습니까? – Paul

+0

필자는 기본 클래스의 paint 이벤트에 대해 빈 함수를 구현해야했습니다. 빨리 고쳐 주셔서 감사합니다 – JonMorehouse

답변

0

paintEvent은 응용 프로그램을 컴파일하고 열 수있는 기능이 있습니다. 하지만 웬일인지, 내 장면을 그릴 때마다 작동하지 않습니다.

그러나 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(); 

?

+1

일반적으로'QGraphicsView :: paintEvent()'를 오버라이드 할 필요는 없으며, 필요한 것을 그리기 위해'QGraphicsObject :: paint()'메소드를 구현하는 대신에. 'Game :: paintEvent()'의 맨 앞에'QGraphicsView :: paintEvent()'를 호출하고 그것이 작동하는지보십시오. – Paul

+0

이봐, 이거 효과가있어. QGraphicsObject :: paintEvent()를 호출하면 모든 것이 잘 수행되었습니다! 감사 – JonMorehouse

관련 문제