I am trying to update some sensor values posted to firebase using QT qml with python as the backend. The values come from different sensors so I'm using a QStandardItemModel and a for loop to iterate through a fetch-link function. For now, the GUI only displays the current value it gets from the server and doesn't update.
- python function to get the firebase link. (3 of these for each parameter)
def fetch_p(self, current_node):
node_id = ('/00' + str(current_node) + '/p')
node_data = firebase.FirebaseApplication('https://link/', None)
result = node_data.get(node_id, None)
return result
- Code for QT model
def __init__(self):
super().__init__()
self._model = QStandardItemModel()
self._model.setItemRoleNames({Qt.DisplayRole: b"custom_name"})
- For loop to create the model items
for i in range(1, 4):
node_id = ("Node 00" + str(i))
pPower = bridge.fetch_p(i)
pAng_y = bridge.fetch_y(i)
pAng_z = bridge.fetch_z(i)
bridge.add_node_card(node_id)
I think the codes above should provide an overview of what I've done. the overall code is lengthy and messy as I am so inexperienced.
what I am having challenges with getting the GUI to keep updating values continuously. I tried using the while loop before the for loop but the app wouldn't launch (loading circle). I have also searched online and found out that this could be best done using Qthread but I'm too inexperienced to implement the codes I found in my program. Finaly, I think it's important I talk about the QMl files. I have a main.qml and a nodecard.qml. the nodecard.qml is created using the ItemModel.
Repeater{
model: backend.model
NodeCard{
id: thisCard
text: model.custom_name
power: backend.powerUpdate()
yAng: backend.tiltAngleY()
zAng: backend.tiltAngleZ()
priority: backend.priorLevel()
}
Any form of help or guidance will be much appreciated.