Results 1 to 3 of 3

Thread: QGraphicsItem's destructor will crash if it has children

  1. #1
    Join Date
    Oct 2010
    Posts
    10
    Thanks
    1

    Default QGraphicsItem's destructor will crash if it has children

    I am using Qt 4.7.3 and create a QML component in C++ (inherits QDeclarativeItem), I found it will crash in the QGraphicsItem's destructor.
    After trace into the code, I found the code snippet seems wrong.

    qgraphicsitem.cpp line:1479

    if (!d_ptr->children.isEmpty()) {
    while (!d_ptr->children.isEmpty())
    delete d_ptr->children.first();
    Q_ASSERT(d_ptr->children.isEmpty());
    }

    The code won't remove the first element after deleted it, and than delete the first element again, so it cause double-free and the program crash.
    Have anyone meet this situation?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsItem's destructor will crash if it has children

    No, you are wrong, you can see few lines below that the item detaches itself from its parent when deleted so it is removed from the list. Please provide a backtrace of your code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2010
    Posts
    10
    Thanks
    1

    Default Re: QGraphicsItem's destructor will crash if it has children

    Quote Originally Posted by wysota View Post
    No, you are wrong, you can see few lines below that the item detaches itself from its parent when deleted so it is removed from the list. Please provide a backtrace of your code.
    I got it, thanks for your explain.

    I have create a clear component and it still crash, the backtrace is following
    crash-callstack.jpg

    And the code of of this component is:

    #ifndef ViewCellExtension_H
    #define ViewCellExtension_H

    #include <QDeclarativeItem>
    class ViewCell;
    class ViewCellExtension : public QDeclarativeItem
    {
    Q_OBJECT
    public:

    public slots:

    private:
    };

    QML_DECLARE_TYPE(ViewCellExtension)
    #endif // ViewCellExtension_H

    Very short, very clean, but it still crash..very stranger, I am still traciing.


    Added after 24 minutes:


    I have solved it. It is the CRT library issue. If the QML extension is linked to static CRT library, it will crash. So I changed it to multi-thread DLL, and it works well now.
    It may some interface design issue here I think.
    Last edited by diro; 9th September 2011 at 10:57.

Similar Threads

  1. Replies: 3
    Last Post: 25th April 2011, 04:40
  2. QSqlQuery crash in destructor
    By seim in forum Qt Programming
    Replies: 5
    Last Post: 22nd January 2010, 23:12
  3. QTableWidget Crash in Destructor
    By mclark in forum Qt Programming
    Replies: 19
    Last Post: 25th July 2008, 15:44
  4. Crash on QString Destructor
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 14th June 2007, 15:28
  5. QList crash in destructor
    By mclark in forum Newbie
    Replies: 7
    Last Post: 6th December 2006, 16:27

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.