There's not much information to go off here, so my answer will be mostly untested pseudo-code.
Updated answer after reading your comment:
I would have a DeviceManager
that stores a list of each device that's plugged in. A DeviceModel
would listen to changes in that list, and expose a device
role (you could also have a role for each property of the device). Create a DeviceUI.qml
that represents the common parts of each device, and within that, have a Repeater
like @eyllanesc mentioned to enumerate each "gain" type represented by a DeviceGainModel
:
// DeviceUi.qml
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 2.15
GroupBox {
id: root
title: device.displayName
required property var device
ColumnLayout {
anchors.fill: parent
Repeater {
model: DeviceGainModel {
device: root.device
}
delegate: RowLayout {
Label {
text: model.gainDisplayName
}
Slider {
value: model.gain
onMoved: model.gain = value
}
}
}
}
}
// main.qml
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 2.15
import MyApp 1.0
ApplicationWindow {
id: window
width: 640
height: 480
visible: true
required property DeviceManager deviceManager
ColumnLayout {
Repeater {
model: DeviceModel {
deviceManager: window.deviceManager
}
delegate: DeviceUi {
// Set via model roles.
required property var device
}
}
}
}
This way, your domain logic knows nothing about the UI (i.e. not accessing QML from C++).