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");
 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
check what the db.lastError() method returns –  Nathan W Jul 17 '12 at 14:23
port=5432 is required even on localhost –  Mapperz Jul 17 '12 at 14:34

1 Answer 1

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


share|improve this answer

Your Answer


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.