QML: ComboBox inside delegateChoice cannot read values from Controls 2 tableView model. (model.display is undefined)

Viewed 455

I have a Controls 2 tableView together with qt.labs.model 1.0. Inside the first DelegateChoice - comboBox, I'm trying to read the value of "group" column (column 3) by using model.display, but display is undefined. Please note that in the second delegateChoice - TextField, I can easily read the column values by using model.display.

Anyway, how can I read the the "group" column inside ComboBox.

TableView {
    id: table 
    anchors.fill: parent
    clip: true
    columnSpacing: 4
    rowSpacing: 4
    columnWidthProvider: column => Math.min(600, model.columnWidth(column))

    model: TableModel {
        id: tableModel
        TableModelColumn { display: "name" }
        TableModelColumn { display: "domain" }
        TableModelColumn { display: "port" }
        TableModelColumn { display: "group" }
        TableModelColumn { display: "status" }
        TableModelColumn { display: "mac" }

        rows: [
            { name:"dev1", domain:"mydomain", port: 3719, group: "group1", status:"available", mac:"192.168.1.1" },
            { name:"dev1", domain:"mydomain", port: 3719, group: "group2", status:"available", mac:"192.168.1.1" }
        ]
    }

    delegate: DelegateChooser {
        DelegateChoice {
            column: 3
            delegate: ComboBox {
                textRole: "text"
                valueRole: "value"
                model: groupsModel
                currentIndex: indexOfValue(model.display)
            }
        }
        DelegateChoice {
            delegate: TextField {
                text: model.display
                implicitWidth: 140
                onAccepted: model.display = text
            }
        }
    }
}
1 Answers

The problem is that there is a conflict between properties since it is observed that the QComboBox has a property "model" that its values are accessed with "model.rolename" that the TableView also has.

One solution is to simply use "display", as a recommendation is that groupsModel does not have that name as a role:

currentIndex: indexOfValue(display)
Related