3

Everything seems to go right, but nothing happens:

layers = QgsProject.instance().mapLayers().values()
for layer in layers:
    if isinstance(layer, QgsVectorLayer):
        dp = layer.dataProvider()
        uri = QgsDataSourceUri(dp.dataSourceUri())
        print ("Origin: ", uri.connectionInfo())

      uri.setDatabase('P:/PG/GEM/BAV20/GEMEINDE365/31717/qgs/wh_2/31717.sqlite')
        #uri.setDatabase('./wh_2/31717.sqlite')
        print ("New:", uri.connectionInfo())
        dp.setDataSourceUri(uri.connectionInfo())
        dp.reloadData()
        layer.dataProvider().forceReload()
        layer.triggerRepaint()

What I am missing?

4

The dataProvider().forceReload() function was removed in QGIS3, the docs are a bit out of date. New in 3.6 is the setDataSource function but it needs ProviderOptions as well so;

layer.setDataProvider(myParams, name, layer type, QgsDataProvider.ProviderOptions())
layer.triggerRepaint() 

https://qgis.org/api/classQgsRasterLayer.html#a733cd12cd1a95248450d0b471996c53b

This works with a wms call havent tried with a DB connecting.

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.