I update a list of WMS connections automatically with QgsSettings(). When the connection doesn't exist, it is well created with all good attributes. But when the connection already exists, and one attribute needs to be updated, the changes are not taken into account in the list of connections in the browser, but when I check the connection with the Python console, the attribute has been changed.
Here is how I do :
settings = QgsSettings()
for s in settings.allKeys():
if s.startswith(my_key):
if settings.value(s) != my_value
settings.setValue(s, my_value)
iface.reloadConnections()
# I also tried :
# settings.sync()
And if I want to modify an existing connection, I need to remove it first, then with this code it is well initialized.
-
1Can you show how you create a new connection, for example by answering: gis.stackexchange.com/questions/329885/… ? I want to learnBera– Bera2025年09月11日 09:21:59 +00:00Commented Sep 11 at 9:21
1 Answer 1
Ok I think I got a part of my answer. When looking at the exact keys created in the QgsSettings, some of the wms-connection keys start with connections/ows/items/wms/connections
(dpi-mode, http-header, ignore-get-map-uri, url) and some with qgis/connections-wms
(password, referer, username). So to update a connection you have to update the right keys.