<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Multiple thanks to both Alessandro and Etienne for helping me
with this question. I owe you both a large cold beer (each !) next
time we meet.<br>
</p>
<pre class="moz-signature" cols="72">Med venlig hilsen / Kind regards
Bo Victor Thomsen</pre>
<div class="moz-cite-prefix">Den 10-01-2021 kl. 04:10 skrev Etienne
Trimaille:<br>
</div>
<blockquote type="cite"
cite="mid:CAMtDFLLtPf8i14QA_iu4S2rT+6m8j++KNn9Uh4LgeL7fOkDLCQ@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">
<div><span class="gmail-pl-s1">The connection API is indeed
convenient for that : <br>
</span></div>
<div><span class="gmail-pl-s1"><br>
</span></div>
<div><span class="gmail-pl-s1">metadata</span> <span
class="gmail-pl-c1">=</span> <span class="gmail-pl-v">QgsProviderRegistry</span>.<span
class="gmail-pl-en">instance</span>().<span
class="gmail-pl-en">providerMetadata</span>(<span
class="gmail-pl-s">'postgres'</span>)</div>
<div><span class="gmail-pl-s1">connection</span> <span
class="gmail-pl-c1">=</span> <span class="gmail-pl-s1"></span><span
class="gmail-pl-s1">metadata</span>.<span
class="gmail-pl-en">findConnection</span>("the postgis
connection name")</div>
<div><span class="gmail-pl-s1">uri</span> <span
class="gmail-pl-c1">=</span> <span class="gmail-pl-v">QgsDataSourceUri</span>(<span
class="gmail-pl-s1">connection</span>.<span
class="gmail-pl-en">uri</span>())</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">Le sam. 9 janv. 2021 à 22:36,
Alessandro Pasotti <<a href="mailto:apasotti@gmail.com"
moz-do-not-send="true">apasotti@gmail.com</a>> a écrit :<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi
Bo,<br>
<br>
you may have a look to<br>
<a
href="https://qgis.org/pyqgis/master/core/QgsProviderRegistry.html?highlight=decodeuri#qgis.core.QgsProviderRegistry.decodeUri"
rel="noreferrer" target="_blank" moz-do-not-send="true">https://qgis.org/pyqgis/master/core/QgsProviderRegistry.html?highlight=decodeuri#qgis.core.QgsProviderRegistry.decodeUri</a><br>
and encodeUri.<br>
<br>
Or better: the connections API<br>
<a
href="https://qgis.org/pyqgis/master/core/QgsAbstractProviderConnection.html"
rel="noreferrer" target="_blank" moz-do-not-send="true">https://qgis.org/pyqgis/master/core/QgsAbstractProviderConnection.html</a><br>
<br>
<br>
<br>
On Sat, Jan 9, 2021 at 2:03 PM Bo Victor Thomsen<br>
<<a href="mailto:bo.victor.thomsen@gmail.com"
target="_blank" moz-do-not-send="true">bo.victor.thomsen@gmail.com</a>>
wrote:<br>
><br>
> Ok, this has me stumped.<br>
><br>
> I know, that I can generate a database URI like this
(example from cookbook):<br>
><br>
> uri = QgsDataSourceUri()<br>
> # set host name, port, database name, username and
password<br>
> uri.setConnection("localhost", "5432", "dbname", "johny",
"xxx")<br>
> # set database schema, table name, geometry column and
optionally<br>
> # subset (WHERE clause)<br>
> uri.setDataSource("public", "roads", "the_geom", "cityid
= 2643")<br>
><br>
> vlayer = QgsVectorLayer(uri.uri(False), "layer name you
like", "postgres")<br>
><br>
><br>
> But I would like to use information from a already
defined Datasource connection from the Datamanager dialog.<br>
><br>
> I suspect, that there must be a
"QgsSettingsConvertToUri_or_whatever_it_is_called()" function
that uses a QGS settings address (ex. like
"/PostgreSQL/connections/MyDatabase" for a Postgresql database
connection) as input and automatically convert the settings
values to a URI string.<br>
><br>
> Is there anyone, that can point me in the right direction
?<br>
><br>
> --<br>
><br>
> Med venlig hilsen / Kind regards<br>
><br>
> Bo Victor Thomsen<br>
><br>
> _______________________________________________<br>
> QGIS-Developer mailing list<br>
> <a href="mailto:QGIS-Developer@lists.osgeo.org"
target="_blank" moz-do-not-send="true">QGIS-Developer@lists.osgeo.org</a><br>
> List info: <a
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer"
rel="noreferrer" target="_blank" moz-do-not-send="true">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
> Unsubscribe: <a
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer"
rel="noreferrer" target="_blank" moz-do-not-send="true">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
<br>
<br>
<br>
-- <br>
Alessandro Pasotti<br>
QCooperative: <a href="http://www.qcooperative.net"
rel="noreferrer" target="_blank" moz-do-not-send="true">www.qcooperative.net</a><br>
ItOpen: <a href="http://www.itopen.it" rel="noreferrer"
target="_blank" moz-do-not-send="true">www.itopen.it</a><br>
_______________________________________________<br>
QGIS-Developer mailing list<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org"
target="_blank" moz-do-not-send="true">QGIS-Developer@lists.osgeo.org</a><br>
List info: <a
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer"
rel="noreferrer" target="_blank" moz-do-not-send="true">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
Unsubscribe: <a
href="https://lists.osgeo.org/mailman/listinfo/qgis-developer"
rel="noreferrer" target="_blank" moz-do-not-send="true">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
</blockquote>
</div>
</blockquote>
</body>
</html>