I've tested the attributeValueChanged
SIGNAL in a created-from-scratch test plugin using QGIS v.2.6.1
You can connect the SIGNAL to your slot this way (I did it in my run()
method):
def run(self):
self.lyr = self.iface.mapCanvas().layers()[0]
self.lyr.attributeValueChanged.connect(self.mySlot)
And then, you have two options to write your slot (see mySlot
and mySlot2
):
def mySlot(self):
QMessageBox.information( self.iface.mainWindow(), "Test",
"Attributes were changed!!!", QMessageBox.Ok )
def mySlot2(self, fid, idx, v):
QMessageBox.information( self.iface.mainWindow(), "Test",
"Attributes changed for feature " + str(fid), QMessageBox.Ok )
Both slots work, just replace self.mySlot
by self.mySlot2
in the connect method above if you want to switch between them.
If you want to get the test plugin, run it on your QGIS, and have a look at the code, you can access to it here. You find installation and usage instructions in the README file.
You're very close. The only issue I see with your code is the PG_OUTPUT
variable, which should actually be a URI like this:
uri = 'postgresql://user:pass@localhost:5432?dbname=my_db&schema=my_schema&project=my_project'
If you have the URI in that way, you can just call:
QgsProject.instance().write(uri)
And now your project will be stored in your DB.
Related:
Best Answer
You can use
iface.actionSaveAllEdits().triggered
signal as below.run
method runs after "Current edits" window is closed. It doesn't matter if the user chooses Yes or No.But As Germán Carrillo mentioned, users could still cancel edits.