动态的酒店的名字分配内部委托

0

的问题

我想包括设置的对象内的代表一中继器,这样我可以保存价值的一个蓝色小方块来实现. 然而,我不能找出如何动态设定的财产的别名。

什么我想要实现的是拥有的财产,别名是一样的modelData. 例如,对于item1:"性别item1:框。值";对于item2:"性别item2:框。值",等等。

Column {
    Repeater {
        model: ["item1", "item2", "item3", "item4", "item5"]
        delegate: RowLayout {
            Settings {
                fileName: "config"
                category: modelData
                property alias value: box.value
            }
            Label {
                text: modelData
            }
            SpinBox {
                id: box
            }
        }
    }
}

上述代码生成的以下设置,是一个工作周围为什么我想要做的:

[item1]
value=""
[item2]
value=""
[item3]
value=""
...

什么我想要的是一个单一的类别的价值,如下所示:

[category]
item1=""
item2=""
item3=""
...
qml qt qt6
2021-11-20 01:36:52
1

最好的答案

1

对于这种情况下你不能使用性能的但是 value()setValue() 方法:

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Qt.labs.settings

ApplicationWindow {
    width: 640
    height: 480
    visible: true

    readonly property var values: ["item1", "item2", "item3", "item4", "item5"]
    Settings {
        id: settings
        category: "category"
    }

    Column {
        Repeater {
            model: values
            delegate: RowLayout {
                id: row_layout
                Label {
                    text: modelData
                }
                SpinBox {
                    id: box
                }
                Component.onCompleted: box.value = settings.value(modelData, 0)
                Component.onDestruction: settings.setValue(modelData, box.value)
            }
        }
    }
}

输出:

[category]
item1=6
item2=6
item3=4
item4=2
item5=2
2021-11-20 02:21:15

这个完美的作品。 我唯一能说的是我设置的onValueChanged酒店的框保存的设置,以便复制的别名的行为。
Vlad

@弗拉德是的,我知道,我会加入它,但是海事组织,它是不必要的拯救他们在所有时间,我喜欢载荷是在开始时存在的结束。
eyllanesc

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................