I have the same problem as Making QGIS layer update from changed data source.
However, I cannot get the solution proposed by Matthias Kuhn in a comment on an answer to that question to work.
I am using QGIS 3.4, I have loaded a .geojson file as a vector layer and am trying to refresh it without removing and re-adding. The map refreshes when I move it but the attribute table is not re-loaded. I may not have understood how to use the reload function so here are my steps, I am using the Python Console.
mc = iface.mapCanvas()
layer = mc.currentLayer()
layer.name()
'radarOutGJTemp' #--- Correct
# Tried the following with errors attached
layer.dataProvider().reload()
AttributeError: 'QgsVectorDataProvider' object has no attribute 'reload'
layer.dataProvider.reload('radarOutGJTemp')
AttributeError: 'builtin_function_or_method' object has no attribute 'reload'
layer.dataProvider.reload(radarOutGJTemp)
AttributeError: 'builtin_function_or_method' object has no attribute 'reload'
I can see the function reload appear in a window as I type. I did try to import reload just in case, that failed but again I could see it appear in the window as I typed.
import reload
ModuleNotFoundError: No module named 'reload'
reload()
belongs to theQgsRasterDataProvider
class. You are working with aQgsVectorDataProvider
object. This class has the methodforceReload()
. Did you try that?dataProvider()
needed to actually call the method,layer.dataProvider().forceReload()
should work. However, I see thatforceReload()
is deprecated and will be removed in Qgis 4. So you could use thereloadData()
method inherited by all subclasses ofQgsDataProvider
. E.g.layer.dataProvider().reloadData()
. I haven't tested mind you- I'm just going off the docs.