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. #16
    Join Date
    Aug 2006
    Location
    istanbul, turkey
    Posts
    42
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Lightbulb Re: QCanvasPolygonalItem delete and SegFault or pure virtual call

    no areaPoints() is pretty good.
    it's inner undocumented problem
    i've just checked source code of qcanvas.cpp

    and surprise appears.
    but thanks to qtcentre.org which leads to me to correct answer.

    at qtcentre.org similar (maybe exactly same) problem was posted before.
    post ends like below:


    Hi

    It has been fixed. Horray. A nice chap at Qt support saw the problem and luckily my example had made the problem worst. Anyway here it is:

    // Note: if you reimplement the boundingRect() function
    //of your QCanvasRectangle subclass and change the values this function
    //returns while the item is visible, sure to call QCanvasPolygonalItem::invalidate().
    // If you do not the QCanvas will use one bounding rectangle when adding the
    // item to the chunks and a different one
    //when removing, causing the internal list of items to still contain your
    //item after it has been hidden. When the item is deleted, QCanvas still
    //believes that the item is visible and uses the pointer and thus your
    //program crashes. You will need to call
    //invalidate() on the item if you do change it.

    I did not realise from the Qt documentation overriding the boundRect() and changing the size would have this effect.

    Cya Illya

    I have seen the same problems about removing properly the QCanvasItem from the QCanvas. But I did not see the satisfying answer.

    I have faced with the same problem. After two days, we found and solved the result as in the following.

    When we try to delete the any items from the QCanvas by using the delete statement, we are facing the problem with resize or some thing like that which causes to call the update function of the QCanvas. In detail, it call the drawUnique() function. Anyway, althoug we delete the QCanvasItem from QCanvas, it stores another list which is a memeber of QCanvasChunk. That is, QCanvas uses another list in order to improve the its performance. It uses chunks which displays the changed items in the QCanvas. Therfore, we have to clear this list as well.

    In order to do that, First, we can put setVisible(false) or hide() or invalidate() functions at the begining of the overloaded areaPoints() function. Then, we can add setVisible(true) or show() or update() functions at the end of the areaPoints() function.


    setVisible() (or the others listed above) call to removeFromChunks() or addChunks() function. So any action which causes to call update function can not reason any conflists between the removed QCanvasItems and the internal list ( the list member of QCanvasChunk ) .

    I think it should be a function of QCanvas which clear the chunks as well and it should be used in the destructor like hide as documented.

    Best regards
    Serhat
    and QCanvasRectangle source code was same to my Cell class except below:

    Qt Code:
    1. void QCanvasRectangle::setSize(int width, int height)
    2. {
    3. if ( w != width || h != height ) {
    4. removeFromChunks(); // ATTENTION HERE
    5. w = width;
    6. h = height;
    7. addToChunks(); // ATTENTION HERE
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    which supports post of Serhat.

    So now, there is no way to reach these functions (removeFromChunks() and addToChunks()) but as post says there is way to accomplish this via other functions.

    Addition to post there is no way to trigger these two functions in areaPoints() because areaPoints() is const.

    i'll check and report test results to you.
    Guess what?
    now it makes sense about pure virtual func call. because it has reference to base class(via chunk list). but real class (derived obj) is deleted. so pure virtual call happens here.


    thanks for interest

    Hayati
    Best Regards
    Last edited by hayati; 13th March 2008 at 17:24.

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.