Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have some questions for you:

I created a python-plugin in QGIS,

then I created a Qt gui fom my plugin

and at last I created a Postgres DB

now I need to make a connection between Qt-gui and Postgres-DB

I wrote this

 from PyQt4.QtSql import *
 db = QSqlDatabase.addDatabase("QPSQL");
 db.setHostName("localhost");
 db.setDatabaseName("siti");
 db.setUserName("postgres");
 db.setPassword("bina");
 bool ok = db.open();

but it doesn't works, I can't understand what I do wrong...

I wish someone could help me...

thank you for all! lisa

share|improve this question
3  
check what the db.lastError() method returns –  Nathan W Jul 17 '12 at 14:23
1  
port=5432 is required even on localhost –  Mapperz Jul 17 '12 at 14:34
add comment

1 Answer

I had also problems with QSqlDatabase, so I used the psycopg2 library instead:

http://wiki.postgresql.org/wiki/Psycopg2_Tutorial

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.