Memory leak returning QIcon
- by Stefano
I started using Qt but I'm facing a big problem: I implemented my custom model that inhrerits from the QAbstractListModel class. What I want to do is to display a list with icon. All works and the image is shown with my code but it creates a memory leak. If I don't return the icon no memory leak is detected.
class MyModel : public QAbstractListModel
{
public:
...
private:
QIcon myicon;
}
QVariant MyModel::data(const QModelIndex &index, int role) const
{
...
if (role == Qt::DecorationRole)
{
return this->myicon;
}
...
}