Ich habe eine Schnittstelle erstellt hat eine ListView und zwei Buttons. Wenn Sie auf Scan Schaltfläche klicken, wird C++ aufgerufen und Änderungen am Modell von ListView vorgenommen. Danach wird C++ ein Signal aussenden, um das Modell zu ändern, daher wird ListView in QML mit dem neuen Modell aktualisiert. Ich möchte, dass BusyIndicator während dieses Vorgangs ausgeführt wird. Wie kann ich das machen ?.Machen Sie BusyIndicator laufen, wenn Sie auf die Schaltfläche klicken (Signal an C++)
Ich sah ein paar Lösungen auf stackoverflow wie diese: BusyIndicator does not show up aber keiner von ihnen arbeitete für meinen Fall.
Kann mir jemand helfen? Vielen Dank.
Hier ist mein qml Code:
import QtQuick 2.5
import QtQuick.Layouts 1.3
import Qt.labs.controls 1.0
Rectangle
{
objectName: "bluetoothPage"
anchors.fill: parent
property var bluetoothDataModel: messageFromApp.bluetoothData
onBluetoothDataModelChanged: listView.update()
signal qmlScanButtonSignal()
signal qmlDisconnectButtonSignal()
ColumnLayout
{
anchors.fill: parent
spacing: 6
RowLayout
{
Layout.fillWidth: true
Text
{
Layout.fillWidth: true
text: "Connect with ECU"
font.bold: true
font.pixelSize: 20
}
BusyIndicator
{
id: busyIndicator
Layout.preferredWidth: 30
Layout.preferredHeight: 30
running: false
visible: false
}
}
GroupBox
{
Layout.fillHeight: true
Layout.fillWidth: true
title: qsTr("Available device:")
ListView
{
id: listView
anchors.fill: parent
model: bluetoothDataModel
delegate: Component
{
Item
{
width: parent.width
height: 40
Column
{
Text { text: "Name:" + model.modelData.name }
Text { text: "Number:" + model.modelData.macAddress }
}
MouseArea
{
anchors.fill: parent
onClicked: listView.currentIndex = index
}
}
}
highlight: Rectangle
{
color: "blue"
}
}
}
RowLayout
{
Layout.fillWidth: true
Layout.preferredHeight: 10
Button
{
Layout.fillHeight: true
Layout.fillWidth: true
text: "Scan"
onClicked: qmlScanButtonSignal()
}
Button
{
Layout.fillHeight: true
Layout.fillWidth: true
text: "Disconnect"
onClicked: qmlDisconnectButtonSignal()
}
}
}
}