Memory leak returning QIcon

Posted by Stefano on Stack Overflow See other posts from Stack Overflow or by Stefano
Published on 2012-04-11T17:25:22Z Indexed on 2012/04/11 17:29 UTC
Read the original article Hit count: 486

Filed under:
|
|

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;
    }

    ...
}

© Stack Overflow or respective owner

Related posts about c++

Related posts about listview