471,330 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

pyqt help for postgres db

1
hi all,
I am new to python and pyqt.
I am using pyqt4 and on windows with ActiveState python2.5
I wish to connect to a postgres database and display a relation in the database on a table in the python gui.
I tried using psycopg2 to connect to the database - it works fine.
But i donot know how to display the cursor in a table .
I tried using QtableView of QtSql but couldnot do it !
can someone help me out by giving me a hint with the code to do that.
By the way my code is as under:-

from PyQt4 import QtCore, QtGui, QtSql
import psycopg2

conn = psycopg2.connect("dbname='test' user='root' host='localhost' password='mypass'")

model= QtSql.QSqlTableModel()
model.setTable("air") # air is the relation in the database.

model.select()
view = QtGui.QTableView()
view.setModel(model)
view.setWindowTitle("Main Window!")
view.show()
Dec 16 '07 #1
0 887

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

10 posts views Thread by Ilya Knizhnik | last post: by
35 posts views Thread by Vamsi Mudrageda | last post: by
8 posts views Thread by simo | last post: by
10 posts views Thread by svenn.are | last post: by
3 posts views Thread by Fabio | last post: by
10 posts views Thread by Simon John | last post: by
4 posts views Thread by Phil Thompson | last post: by
17 posts views Thread by eholbroo | last post: by
3 posts views Thread by Phil Thompson | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.