Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QAbstractListModel resetModel lags
Forum Updated to NodeBB v4.3 + New Features

QAbstractListModel resetModel lags

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dmitry89
    wrote on last edited by
    #1

    I use QAbstractListModel with my ListView. The delegate of the ListView consist of 19 Rectangles with Text. When I reset the model, it takes about 300ms to recreate 1 delegate item. If there are 20-30 items in the new model data, it takes 5-6 sec. If I reset the model 2-3 times, it crashes with an error at this line:
    endResetModel();
    Is there a faster way to update a ListView content and how can I fix this crash problem?
    Here is my minimized code:
    @

    QVariant TargetsModel::data(const QModelIndex & index, int role) const {
    return QVariant(0); //does not matter
    }
    void TargetsModel::setModel(int ship, TableData &model)
    {
    beginResetModel();
    m_data.replace(model); //Just replace old vector
    endResetModel();
    }
    @

    ListView delegate:

    @
    Column {
    id: column
    property double firstblockwidth: Math.round(column.width/17*7)
    width: parent.width
    spacing: 0

    Row {
        z: 20
        spacing: 0
        CustomNumberField {
            width: Math.round(column.firstblockwidth/3)
            value:  complexnum
        }
        CustomNumberField {
            width: Math.round(column.firstblockwidth/3*2)-x
            value:  mcnum
        }
        CustomNumberField {
            width: Math.round(column.width/17*10.5)-x
            value: vip
        }
        CustomNumberField {
            width: Math.round(column.width/17*13)-x
            value: bearing
        }
        CustomNumberField {
            width: Math.round(column.width)-x
            value: distance/1000.0
        }
    }
    

    }
    @

    CustomNumberField:

    @
    Rectangle {
    id: numberfield
    property alias font: textfield.font
    property var value: 0
    property real minimumValue: 0
    property real maximumValue: 0
    property real decimals: 2

    property string background: "#2f2f2f"
    
    property bool edited: false
    width: 25
    height: 25
    color: "#2f2f2f"
    border.width: 1
    border.color: "#6d6d6d"
    Text {
        id: textfield
        font.pointSize: 10
        font.family: arialFont.name
        anchors.fill: parent
        anchors.margins: 2
        verticalAlignment: Qt.AlignVCenter
        text: numberfield.value
        color: "white"
    }
    

    }
    @

    Due to the non-standard shape of the delegate I can't use TableView (2 rows with different number of items)

    1 Reply Last reply
    0
    • M Offline
      M Offline
      morte
      wrote on last edited by
      #2

      Hi, did you try to notify view of changes (beginInsertRows()/endInsertRows(), beginMoveRows()/endMoveRows(), etc.) instead of resetting whole model?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved