PDA

View Full Version : trouble with QSqlRelationalTableModel and setFilter



yleesun
31st July 2008, 08:03
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..

Auryn
31st July 2008, 08:59
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:


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'");


If I am wrong, please, send more information about your problem.

yleesun
31st July 2008, 09:18
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:

m_Modle->setTable(tabName);
m_Modle->setFilter(fiterstring);
m_Modle->setRelation(1,QSqlRelation(reTabName,reFieldName,r eDisName));

m_Modle->select();
m_pShowTree->setModel(m_Modle);

then no data was outputted;

msh
22nd November 2008, 16:01
Has anybody solved this problem?

Lesiok
23rd November 2008, 10:39
What is in : tabName, fiterstring, reTabName, reFieldName and reDisName ?
I'm asking because in my code all is working perfect.

bmn
3rd March 2009, 07:02
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).