I'm trying to update layer of a QgsProject instance with a timer in a new thread and show the updated data in a QMainWindow. But however I change the attributes/features/layers, it always freezes the application. I understand that the QgisProject lives in the main thread, so is it even possible to change a layer without freezing the application? If yes how?
The code below is what im trying to do in an extra thread.
self.project = QgsProject.instance()
layer = self.project.mapLayersByName(layerName)[0]
keyColIdx = layer.fields().indexOf(keyCol)
with edit(layer):
for feat in layer.getFeatures():
for colToEdit in colsToEdit:
colToEditIdx = layer.fields().indexOf(colToEdit)
try:
# get item from dataframe
value = newDf[newDf[keyCol] == str(feat.attributes()[keyColIdx])][colToEdit].item()
# change attribute
layer.changeAttributeValue(feat.id(), colToEditIdx, value)
except:
pass
canvas.refresh()