My Dev setup:
Qt version : Qt 5.15.0
OS: Embedded Linux

I have a list of information.
Assume I have a structure called MyStruct
My model class is having a member variable of QList of above structure, to hold data for my view. Whenever I am opening the view, I am updating the QList (Note: There may or may not be a change). Updating here is something like assigning a new QList to existing one. before assignment, I am calling beginResetModel and after assignment I am calling endResetModel,

void MyModelClass::SomeInsertMethod(const QList<MyStruct>& aNewData)
{
    beginResetModel();
    m_lstData = aNewData;
    endResetModel();
}

One thing I believe can be improved, is putting a check, if the new data is different than the existing data and then doing the above. Something like this:

void MyModelClass::SomeInsertMethod(const QList<MyStruct>& aNewData)
{
    if  (m_lstData != aNewData)
    {
        beginResetModel();
        m_lstData = aNewData;
        endResetModel();
    }
}

Apart from that, is there any possibilities of getting a performance issue for calling beginResetModel/endResetModel? I m seeing a very small delay in the view coming up in my application.
I checked the documentation of QAbstractItemModel for above methods. Didn't get anything specific to the performance issue.
The other way, which this can be done, is by individually comparing the elements of the lists and triggering a dataChanged signal with appropriate model index and roles. But I feel, this will unnecessarily introduce some additional loops and comparisons, which again may cause some other performance issue. Correct me if I am wrong.
Is there any advantage of using dataChanged over beginResetModel/EndResetModel?
Please let me know your views on the above.

0

There are 0 answers