Subclassing QGraphicsView crash the app
Hello all!
I am trying to subclass QGraphicsView, but its crashing the app.
How can I do that.
fluxocaixagraphicsview.h
Code:
#ifndef FLUXOCAIXAGRAPHICSVIEW_H
#define FLUXOCAIXAGRAPHICSVIEW_H
#include <QGraphicsView>
#include <QGraphicsScene>
//#include <QGraphicsLineItem>
{
public:
explicit fluxoCaixaGraphicsView
(QWidget *parent
= 0);
~fluxoCaixaGraphicsView();
private:
protected:
};
#endif // FLUXOCAIXAGRAPHICSVIEW_H
fluxocaixagraphicsview.cpp
Code:
#include "fluxocaixagraphicsview.h"
fluxoCaixaGraphicsView
::fluxoCaixaGraphicsView(QWidget *parent
) :{
}
fluxoCaixaGraphicsView::~fluxoCaixaGraphicsView()
{
}
void fluxoCaixaGraphicsView
::showEvent(QShowEvent *event
) {
}
void fluxoCaixaGraphicsView
::resizeEvent(QResizeEvent *event
) {
}
calling it
Code:
QWidget *MainWindow
::criaEstruturaNovoIvestimento() {
//code here
fluxoCaixaGraphicsView *graphicsViewFluxoCaixa = new fluxoCaixaGraphicsView(boxInvestimento3);
//code here
}
Thanks a lot
Re: Subclassing QGraphicsView crash the app
Code:
fluxoCaixaGraphicsView
::fluxoCaixaGraphicsView(QWidget *parent
) :{
}
you just declared a local variable named "cenario", it is not the same as your "cenario" in the header file
change this to
Code:
fluxoCaixaGraphicsView
::fluxoCaixaGraphicsView(QWidget *parent
) :{
}
btw. you should call base class implementation of the reimplemented event handlers.
Re: Subclassing QGraphicsView crash the app
Also need to insert the Q_OBJECT macro in the fluxoCaixaGraphicsView class definition:
Code:
{
Q_OBJECT
public:
explicit fluxoCaixaGraphicsView
(QWidget *parent
= 0);
~fluxoCaixaGraphicsView();
// ...
};