I am trying to show the progress in the progress bar, but it is not running, I have seen several solutions but none has solved me.
This is part of the code that I am using :
def progress_changed(self, progress):
self.progressalg.setValue(progress)
def AdicionarDatosparcelas(self):
self.usuario_origen = self.cfgdlg.v_usuario_o.text()
self.contrasena_origen = self.cfgdlg.v_contrasena_o.text()
self.usuario_destino = self.cfgdlg.v_usuario_d.text()
self.contrasena_destino = self.cfgdlg.v_contrasena_d.text()
progressMessageBar = self.iface.messageBar().createMessage("Insertando parcelas en la base de datos...")
self.progressalg = QProgressBar()
self.progressalg.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
progressMessageBar.layout().addWidget(self.progressalg)
self.iface.messageBar().pushWidget(progressMessageBar, Qgis.Info)
f = QgsProcessingFeedback()
f.progressChanged.connect(self.progress_changed)
geom_column = None
uri_origen = QgsDataSourceUri()
uri_origen.setConnection(self.servidor_origen, str(self.puerto_origen), self.basedato_origen, self.usuario_origen,
self.contrasena_origen,
QgsDataSourceUri.SslDisable)
uri_origen.setParam('key', 'mi_prinx')
uri_origen.setParam('checkPrimaryKeyUnicity','0')
uri_origen.setDataSource("catastro", "parcelas", geom_column)
parcela_origen = QgsVectorLayer(uri_origen.uri(), 'parcela_origen', "postgres")
QgsProject.instance().addMapLayer(parcela_origen, True)
uri_destino = QgsDataSourceUri()
uri_destino.setConnection(self.servidor_destino, str(self.puerto_destino), self.basedato_destino,
self.usuario_destino, self.contrasena_destino,
QgsDataSourceUri.SslDisable)
uri_destino.setParam('key', 'mi_prinx')
uri_origen.setParam('checkPrimaryKeyUnicity', '0')
uri_destino.setDataSource("catastro", "parcelas", geom_column)
parcela_destino = QgsVectorLayer(uri_destino.uri(), 'parcela_destino', "postgres")
QgsProject.instance().addMapLayer(parcela_destino, True)
processing.run("etl_load:appendfeaturestolayer", {
'SOURCE_LAYER': parcela_origen,
'SOURCE_FIELD': 'mi_prinx',
'TARGET_LAYER': parcela_destino,
'TARGET_FIELD': 'mi_prinx',
'ACTION_ON_DUPLICATE': 1}, feedback=f)
self.iface.messageBar().pushSuccess('parcelas exportadas', '')