a sample demostration is like below
class Cell : public QCanvasPolygonalItem {
//...
}
Cell::Cell(QCanvas* canvas)
: QCanvasPolygonalItem(canvas)
{
setBrush( gray );
}
Cell::~ Cell()
{
hide();
}
QPointArray Cell::areaPoints() const
{
QPointArray a(4);
//getCellWidth() and getCellHeight() returns an int value depended to width and height of the canvasitem and they are not virtual
a.
setPoint(0,
QPoint( (int)x
(),
(int)y
() ) );
a.
setPoint(1,
QPoint( (int)x
() + getCellWidth
(),
(int)y
() ) );
a.
setPoint(2,
QPoint( (int)x
() + getCellWidth
(),
(int)y
() + getCellHeight
() ) );
a.
setPoint(3,
QPoint( (int)x
(),
(int)y
() + getCellHeight
() ) );
return a;
}
// at the gui class deletion occurs as below
// m_cell is type of std::vector<Cell*>
void GUI::deleteCell(Cell* c)
{
for( vector<Cell*>::iterator it = m_cells.begin(); it != m_cells.end(); it++){
if ((*it) == c) { // check if it's what we seek
m_cells.erase(it);
break;
}
}
delete c;
c = NULL;
m_canvas->setAllChanged();
m_canvas->update();
}
class Cell : public QCanvasPolygonalItem {
//...
}
Cell::Cell(QCanvas* canvas)
: QCanvasPolygonalItem(canvas)
{
setBrush( gray );
}
Cell::~ Cell()
{
hide();
}
QPointArray Cell::areaPoints() const
{
QPointArray a(4);
//getCellWidth() and getCellHeight() returns an int value depended to width and height of the canvasitem and they are not virtual
a.setPoint(0, QPoint( (int)x(), (int)y() ) );
a.setPoint(1, QPoint( (int)x() + getCellWidth(), (int)y() ) );
a.setPoint(2, QPoint( (int)x() + getCellWidth(), (int)y() + getCellHeight() ) );
a.setPoint(3, QPoint( (int)x(), (int)y() + getCellHeight() ) );
return a;
}
// at the gui class deletion occurs as below
// m_cell is type of std::vector<Cell*>
void GUI::deleteCell(Cell* c)
{
for( vector<Cell*>::iterator it = m_cells.begin(); it != m_cells.end(); it++){
if ((*it) == c) { // check if it's what we seek
m_cells.erase(it);
break;
}
}
delete c;
c = NULL;
m_canvas->setAllChanged();
m_canvas->update();
}
To copy to clipboard, switch view to plain text mode
when i run the program in gdb or valgrind pure virtual func call or segfault caught in:
#0 0x4044132c in QCanvasItemList::drawUnique(QPainter&) () from /usr/lib/libqt.so.3
#1 0x40443dfb in QCanvas::drawCanvasArea(QRect const&, QPainter*, bool) ()
from /usr/lib/libqt.so.3
#2 0x4044368b in QCanvas::drawChanges(QRect const&) () from /usr/lib/libqt.so.3
#3 0x40443196 in QCanvas::update() () from /usr/lib/libqt.so.3
#4 0x404426cc in QCanvas::advance() () from /usr/lib/libqt.so.3
#5 0x40527cf4 in QCanvas::qt_invoke(int, QUObject*) () from /usr/lib/libqt.so.3
#6 0x402a302a in QObject::activate_signal(QConnectionList*, QUObject*) () from /usr/lib/libqt.so.3
#7 0x402a2ee7 in QObject::activate_signal(int) () from /usr/lib/libqt.so.3
#8 0x40505314 in QTimer::timeout() () from /usr/lib/libqt.so.3
#9 0x402bf3bf in QTimer::event(QEvent*) () from /usr/lib/libqt.so.3
#10 0x4024f2c6 in QApplication::internalNotify(QObject*, QEvent*) () from /usr/lib/libqt.so.3
#11 0x4024ef43 in QApplication::notify(QObject*, QEvent*) () from /usr/lib/libqt.so.3
#12 0x4022e2f3 in QEventLoop::activateTimers() () from /usr/lib/libqt.so.3
#13 0x4020f27d in QEventLoop:
rocessEvents(unsigned) () from /usr/lib/libqt.so.3
#14 0x402606cb in QEventLoop::enterLoop() () from /usr/lib/libqt.so.3
#15 0x40260588 in QEventLoop::exec() () from /usr/lib/libqt.so.3
#16 0x4024f4c0 in QApplication::exec() () from /usr/lib/libqt.so.3
so if i understand correct, it crashes after
m_canvas->update()
m_canvas->update()
To copy to clipboard, switch view to plain text mode
but same post clearly points that it's because a pure virtual func call. (which is done in QCanvas::update() i think, but i'm not sure off course)
Bookmarks