I have a system where a process is continuously pushing new earthquake data into a PostGIS database, The data are displayed in QGIS having a layer that is updating each 60 sec. This works fine to display the data, but I would like to do a bit more. Is it somehow possible to connect a Python script to the layer so that it is run each time the layer is updated?

I would only need to run it when the layer is changed (i.e. new data are coming in) but it would not cause any problem if it is run each time the layer is updated (i.e. each 60 sec)

Edit: Following the pointer from @Matt I ran the following code in the Python Console:

def onUpdate():
    iface.messageBar().pushMessage("For info", "updated", level=Qgis.Info, duration=3)


I expected to get a messagebar and a printed message each time my layer was updated, but nothing is happening, so something still is wrong.

(The layer is updated in three ways: The postgisdatabase behind the layer may be updated (I do not expect that to trigger anything), then the layer is being automatically updated each 60 sec - (I expected that to trigger onUpdate to run) and I have manually updated the layer (Update SQL layer - Update) In neither case was the onUpdate triggered.

1 Answer 1


You can connect a function to the QgsVectorLayer.layerModified() signal.

See this answer where I perform a spatial join when a layer is edited. You can swap out the function for your own procedure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.