<p>I'm using the same ip address, same user name and same password to 
make connection. What could cause QtSqlDatabase to fail connection where
 psycopg2 has no problem? Am I missing something? Do both of them 
connect to the same port by default? Anyway to view more detail error 
message of QtSql?</p>

<p>psycopg2</p><p><br></p><p></p><pre class="default prettyprint"><code><span class="pln">conn </span><span class="pun">=</span><span class="pln"> psycopg2</span><span class="pun">.</span><span class="pln">connect</span><span class="pun">(</span><span class="str">"dbname='byrd' host='192.168.1.6' user='xxx' password='xxx'"</span><span class="pun">)</span><span class="pln"><br>
cur </span><span class="pun">=</span><span class="pln"> conn</span><span class="pun">.</span><span class="pln">cursor</span><span class="pun">()</span><span class="pln"><br>cur</span><span class="pun">.</span><span class="pln">execute</span><span class="pun">(</span><span class="str">"SELECT * FROM project"</span><span class="pun">)</span><span class="pln"><br>
results </span><span class="pun">=</span><span class="pln"> cur</span><span class="pun">.</span><span class="pln">fetchall</span><span class="pun">()</span><span class="pln"><br></span><span class="kwd">for</span><span class="pln"> result </span><span class="kwd">in</span><span class="pln"> results</span><span class="pun">:</span><span class="pln"><br>
    </span><span class="kwd">print</span><span class="pln"> result</span></code></pre><pre class="default prettyprint"><code><span class="pln">output </span><span class="pun">--</span><span class="pln"> </span><span class="pun">(</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="str">'Byrdland_and_king'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'P:\\\\Byrdland_and_king'</span><span class="pun">)</span><span class="pln"><br>
</span></code></pre><pre class="default prettyprint"><code><span class="pun"><br></span></code></pre><pre class="default prettyprint"><code><span class="pun">QtSql</span></code></pre><pre class="default prettyprint"><code><span class="pun"><br>
</span></code></pre><pre class="default prettyprint"><code><span class="pun"><pre class="default prettyprint"><code><span class="pln">db </span><span class="pun">=</span><span class="pln"> </span><span class="typ">QtSql</span><span class="pun">.</span><span class="typ">QSqlDatabase</span><span class="pun">.</span><span class="pln">addDatabase</span><span class="pun">(</span><span class="str">"QPSQL"</span><span class="pun">)</span><span class="pln"><br>
db</span><span class="pun">.</span><span class="pln">setDatabaseName</span><span class="pun">(</span><span class="str">"byrd"</span><span class="pun">)</span><span class="pln"><br>db</span><span class="pun">.</span><span class="pln">setHostName</span><span class="pun">(</span><span class="str">"192.168.1.6"</span><span class="pun">)</span><span class="pln"><br>
db</span><span class="pun">.</span><span class="pln">setUserName</span><span class="pun">(</span><span class="str">"xxx"</span><span class="pun">)</span><span class="pln"><br>db</span><span class="pun">.</span><span class="pln">setPassword</span><span class="pun">(</span><span class="str">"xxx"</span><span class="pun">)</span><span class="pln"><br>
<span class="pln">db</span><span class="pun">.</span><span class="pln">open</span><span class="pun">()</span></span></code></pre><pre class="default prettyprint"><code><span class="pln">output </span><span class="pun">--</span><span class="pln"> </span><span class="kwd">False</span><span class="pln"><br>
</span></code></pre></span></code></pre><p></p>