Hi, guys.
Here is a simple of dynamically creating many pairs of SpinBox and Sliders, I want to connect the value of each SpinBox to the value of it’s corresponding Slider.
import QtQuick 2.3
import QtQuick.Controls 1.2
ApplicationWindow {
visible: true
width: 400
height: 300
color: Qt.rgba(0, 0, 0, 1)
function createControl(itemType, where)
{
return Qt.createQmlObject("import QtQuick.Controls 1.2; "
+ itemType
+ " {}",
where,
"ApplicationWindow")
}
Component.onCompleted: {
// Create some controls.
for (var i = 0; i < 10; i++) {
var slider = createControl("Slider", grid)
var spinBox = createControl("SpinBox", grid)
// Connect the SpinBox to the Slider.
// This is what I want but doesn't work.
// slider.valueChanged.connect(spinBox.setValue)
// spinBox.valueChanged.connect(slider.setValue)
}
}
Grid {
id: grid
columns: 2
anchors.fill: parent
}
}
Some ideas?
↧