小编K.T*_*lis的帖子

model.rowCount() 不会绑定到 Item 的属性

我有一个ListViewrootModelQml 内部命名的自定义 C++ 模型初始化的。模型继承QAbstractListModel并将 a 定义QVector<customType>为私有成员以填充模型。

在 my 中,ApplicationWindow我创建了一个,Dialog在其中更改模型并调用setList()函数来更新它。这工作正常。

我还想将模型的大小连接到 aScrollViewint属性。此属性将定义childrena 的RowLayout

问题是,当我尝试将此属性绑定到模型的大小时,应用程序崩溃了。

仅供参考,模型的所有修改都遵循 Qt 的规则。rowCount()Q_INVOKABLE。我也尝试过使用onModelChanged处理程序,但这没有用(我在文档中检查了这个信号是在发出时modelReset()发出的,这是setList()通过内部发生的endResetModel()

我相信这是一个简单的过程(已经在我的项目中多次执行了属性绑定)但没有按预期工作。

我引用了我的项目的一些示例代码。

//main.qml
ConfiguredChannels{
    id: configuredList
    anchors{
        left: parent.left
        top: devices.bottom
        right: tabs.left
        bottom: parent.bottom
    }
}

TabArea {
    id: tabs
    y: toolBar.height
    x: parent.width / 8
    anchors {
        top: toolBar.bottom …
Run Code Online (Sandbox Code Playgroud)

qt scrollview qml qtquickcontrols2

3
推荐指数
1
解决办法
1629
查看次数

标签 统计

qml ×1

qt ×1

qtquickcontrols2 ×1

scrollview ×1