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?
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.
1 Attachment(s)
Re: QGraphicsItem's destructor will crash if it has children
Quote:
Originally Posted by
wysota
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
Attachment 6833
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.