I am working with python plugins for qgis.I am using python2.5 and pyqt4 designer.I used QTreeView on my .ui file.
I wanted to display all the tables from database into QTreeView as the result of the query.
The query is as follows:
cursor.execute("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'")
I am using PostgresSQL as database.Database connection is done using psycopg2 tool.
How to display result of above query into QTreeView in python??
QTreeViewrequires a Model/View framework, so you need to provide a model to work with it. If you are set on usingpsycopg2, you need to build and populate your own model by sub-classingQAbstractItemModelfrom that query.Alternatively, and more easily, you can use the Qt’s
QSqlmodule. It supports PostgreSQL and provides ready-made models (likeQSqlTableModel,QSqlRelationalTableModelorQSqlQueryModel) that you can use withQTreeView.