[PyQt] QSqlTableModel and complex queries

Scott Frankel frankel at circlesfx.com
Thu Sep 25 21:12:12 BST 2008


Hello,

What's the proper way to perform sql SELECT statements to populate a  
table model, when the statement is more complex than select(),  
filters, and order clauses can handle?


According to the Qt documentation, QSqlTableModel.setQuery should  
"normally" not be called on a QSqlTableModel.  Are there circumstances  
when setQuery() should be used?  Is a non-persistent table a germane  
example?  Or is there a better way?

Note that the attached code file creates a simple example with two  
tables, populates them with dummy data, then attempts to perform a  
select on them with a call to setQuery() -- which fails.

 From the documentation and examples, using the table model's  
setTable() method is quite clear for populating the model with data  
from a persistent table.  In my example, I want to populate the model  
with data from multiple fields taken from several tables.  Am I'm  
missing something obvious?  This seems beyond the scope of  
QSqlRelationalTableModel.

Thanks in advance!
Scott


-------------- next part --------------
A non-text attachment was scrubbed...
Name: queryTest.py
Type: text/x-python-script
Size: 4495 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20080925/03ea59d4/queryTest.bin
-------------- next part --------------



More information about the PyQt mailing list