[Interest] copying the object in the delegate

Stan Morris pixelgrease at gmail.com
Sun Oct 20 18:10:13 CEST 2019


The row index changes few times in comparison to the number of times data
is called. Reduce the number of times your code instances a new object by
caching the object and creating a new one only when the row index changes.

Something like:

    QVariant data(const QModelIndex &index, int role) override
    {
        static int lastRow = -1;
        static QScopedPoint<MyDataClass> lastObj;
        if (lastObj.isNull() || index.row() != lastRow) {
            lastRow = index.row();
            lastObj.reset(createDataForRow(lastRow);
        }

/Stan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20191020/8e7c4bc2/attachment.html>


More information about the Interest mailing list