<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Ok, this has me stumped.</p>
<p>I know, that I can generate a database URI like this (example
from cookbook):</p>
<pre><span class="n">uri</span> <span class="o">=</span> <span class="n">QgsDataSourceUri</span><span class="p">()</span>
<span class="c1"># set host name, port, database name, username and password</span>
<span class="n">uri</span><span class="o">.</span><span class="n">setConnection</span><span class="p">(</span><span class="s2">"localhost"</span><span class="p">,</span> <span class="s2">"5432"</span><span class="p">,</span> <span class="s2">"dbname"</span><span class="p">,</span> <span class="s2">"johny"</span><span class="p">,</span> <span class="s2">"xxx"</span><span class="p">)</span>
<span class="c1"># set database schema, table name, geometry column and optionally</span>
<span class="c1"># subset (WHERE clause)</span>
<span class="n">uri</span><span class="o">.</span><span class="n">setDataSource</span><span class="p">(</span><span class="s2">"public"</span><span class="p">,</span> <span class="s2">"roads"</span><span class="p">,</span> <span class="s2">"the_geom"</span><span class="p">,</span> <span class="s2">"cityid = 2643"</span><span class="p">)</span>
<span class="n">vlayer</span> <span class="o">=</span> <span class="n">QgsVectorLayer</span><span class="p">(</span><span class="n">uri</span><span class="o">.</span><span class="n">uri</span><span class="p">(</span><span class="kc">False</span><span class="p">),</span> <span class="s2">"layer name you like"</span><span class="p">,</span> <span class="s2">"postgres"</span><span class="p">)
</span></pre>
<span class="p"></span><br>
<span class="p">But I would like to use information from a already
defined Datasource connection from the Datamanager dialog. </span><br>
<span class="p"></span><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>
<p><span class="p"></span>Is there anyone, that can point me in the
right direction ? <br>
</p>
<p>-- </p>
<pre class="moz-signature" cols="72">Med venlig hilsen / Kind regards
Bo Victor Thomsen</pre>
</body>
</html>