Results 1 to 17 of 17

Thread: QCanvasPolygonalItem delete and SegFault or pure virtual call

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    Aug 2006
    Location
    istanbul, turkey
    Posts
    42
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QCanvasPolygonalItem delete and SegFault or pure virtual call

    a sample demostration is like below

    Qt Code:
    1. class Cell : public QCanvasPolygonalItem {
    2. //...
    3. }
    4.  
    5.  
    6. Cell::Cell(QCanvas* canvas)
    7. : QCanvasPolygonalItem(canvas)
    8. {
    9. setBrush( gray );
    10. }
    11.  
    12. Cell::~ Cell()
    13. {
    14. hide();
    15. }
    16.  
    17. QPointArray Cell::areaPoints() const
    18. {
    19. QPointArray a(4);
    20.  
    21. //getCellWidth() and getCellHeight() returns an int value depended to width and height of the canvasitem and they are not virtual
    22. a.setPoint(0, QPoint( (int)x(), (int)y() ) );
    23. a.setPoint(1, QPoint( (int)x() + getCellWidth(), (int)y() ) );
    24. a.setPoint(2, QPoint( (int)x() + getCellWidth(), (int)y() + getCellHeight() ) );
    25. a.setPoint(3, QPoint( (int)x(), (int)y() + getCellHeight() ) );
    26.  
    27. return a;
    28. }
    29.  
    30.  
    31. // at the gui class deletion occurs as below
    32. // m_cell is type of std::vector<Cell*>
    33. void GUI::deleteCell(Cell* c)
    34. {
    35. for( vector<Cell*>::iterator it = m_cells.begin(); it != m_cells.end(); it++){
    36. if ((*it) == c) { // check if it's what we seek
    37. m_cells.erase(it);
    38. break;
    39. }
    40. }
    41. delete c;
    42. c = NULL;
    43.  
    44. m_canvas->setAllChanged();
    45. m_canvas->update();
    46. }
    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
    Qt Code:
    1. 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)
    Last edited by hayati; 12th March 2008 at 20:43.

Similar Threads

  1. QItemDelegate problem
    By WinchellChung in forum Newbie
    Replies: 2
    Last Post: 5th December 2007, 16:16
  2. c++, placement delete upon exception
    By stinos in forum General Programming
    Replies: 6
    Last Post: 31st October 2006, 15:38
  3. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.