I use QSqlRelationalTableModel with QTableView .when I setFilter to the QSqlRelationalTableModel ,it does not work ,and no data was displayed in the tabview.
please help me,thanks..
I use QSqlRelationalTableModel with QTableView .when I setFilter to the QSqlRelationalTableModel ,it does not work ,and no data was displayed in the tabview.
please help me,thanks..
Perhaps your filter criteria is incorrect.
I use QSqlRelationalTableModel on Qt 4.3 with PostgreSQL 8.3.3.
To filter numeric values I use comparison operators (=, <, >, >=, <=).
To filter strings I use "LIKE" (case sensitive) or "ILIKE" (case insensitive, only for PostgreSQL) and the wildcard %.
Examples:
Qt Code:
my_model.setFilter("my_table.my_numeric_field > 162"); my_model.setFilter("my_table.my_numeric_field = 162"); my_model.setFilter("my_table.my_text_field ILIKE '%substring%'"); my_model.setFilter("my_table.my_text_field ILIKE 'begin_string%'"); my_model.setFilter("my_table.my_text_field ILIKE '%end_string'");To copy to clipboard, switch view to plain text mode
If I am wrong, please, send more information about your problem.
Auryn
Starting to learn the world of Qt
thanks for replying.
I mean than the setRelation and setFilter can not work together.
when I set both ,it does not work ,but anyone of the two can work alone.
the code:
Qt Code:
m_Modle->setTable(tabName); m_Modle->setFilter(fiterstring); m_Modle->select(); m_pShowTree->setModel(m_Modle);To copy to clipboard, switch view to plain text mode
then no data was outputted;
Last edited by jpn; 31st July 2008 at 21:39. Reason: missing [code] tags
Has anybody solved this problem?
What is in : tabName, fiterstring, reTabName, reFieldName and reDisName ?
I'm asking because in my code all is working perfect.
Try an absolute path (tableName.columnName syntax) in your Filter clause. E.g.
model->setFilter("blah.id = 1")
vs.
model->setFilter("id = 1")
If you look at the resultant SQL statement you'll notice that a join on two or more tables is performed when you use a QSqlRelationTableModel, therefore there could be multiple fields with the same name (particularly if your column is named something like id).
Bookmarks