2

I'm working on integrating QGIS and PostGIS, but looking for a way to force a layer reload. I don't need it to be automated -- I'm happy to run a command every time I want to refresh the map. The comments on this question:

How to refresh the attribute table of a layer after editing the table in the DB-Manager?

Suggest that layer.dataProvider().forceReload(); is one option, but when I open Plugins > Python Console and run that I get an error:

layer.dataProvider().forceReload();
Traceback (most recent call last):
  File "<input>", line 1, in <module>
NameError: name 'layer' is not defined

I thought maybe I needed to use the name of my layer, but that didn't fix it:

example.dataProvider().forceReload();
Traceback (most recent call last):
  File "<input>", line 1, in <module>
NameError: name 'example' is not defined

Am I misunderstanding that suggestion? Is there another way to accomplish this in the python console?

  • did u assign any value to layer ? (dumb question ...) – snaileater Apr 2 '18 at 6:48
  • 2
    something like layer = QgsMapLayerRegistry.instance().mapLayersByName("YOUR_LAYER_NAME")... – snaileater Apr 2 '18 at 6:53
  • @snaileater ahhh. ty – Amanda Apr 2 '18 at 23:06

Your Answer

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

Browse other questions tagged or ask your own question.