TreeView:模型参考错误

时间:2018-04-30 10:11:44

标签: qt qml

我有以下TreeView

   TreeView {
        id: view
        anchors.fill: parent
        sortIndicatorVisible: true
        model: fileSystemModel
        rootIndex: rootPathIndex
        selection: sel
        selectionMode: 2

        TableViewColumn {
            id: namecolumn
            title: "Name"
            role: "fileName"

            resizable: true
            width: parent.width-sizeWidth-dateWidth-scrollBarWidth
            delegate: ItemDelegate {
                id: fileCheckDelegate
                Row{CheckBox{
                    id: cbox
                    y: -4
                    }
                    Text{text: model.fileName
                        width: namecolumn.width-x-cbox.width
                        elide: Text.ElideRight
                    }
                 }
                ToolTip {
                    parent: fileCheckDelegate
                    visible: hovered
                    delay: 1000
                    text: qsTr(model.fileName)
                }
            }

        }
    }

所有内容都正确显示,但在终端中我收到以下许多消息:

qrc:/FileSystem.qml:49: TypeError: Cannot read property 'fileName' of null
qrc:/FileSystem.qml:57: TypeError: Cannot read property 'fileName' of null

位置位于我的代表中,一次位于Text text: model.fileName,一次位于ToolTip text: qsTr(model.fileName)。正如我所说,一切都正确显示,但我担心这个错误可能仍然会给我带来问题。我做错了什么?

修改:如果我使用styleData.value代替model.fileName,似乎就是一种解决方法。不过,我不明白为什么我不能写model.fileName

0 个答案:

没有答案