PDA

View Full Version : QSqlTableModel and LIKE



JeanC
9th January 2008, 19:51
Hi it's me again :)

How can I filter a QSqlTableModel so that only rows show up that have a certain cell contain a substring, like the sql LIKE clause?
The setFilter() member filters only on the whole string.

I tried a query like:



QString str = QString("SELECT * FROM pix WHERE 'name' LIKE '%%1%'").arg(nameEdit->text());
QSqlQuery query(str);
model->select();


But this seems not the way to go.

Thanks.

jacek
10th January 2008, 00:01
Use setFilter( QString("name LIKE '%%1%'").arg( str ) ), but make sure that "str" doesn't contain any malicious content.

JeanC
10th January 2008, 09:45
Thanks jacek, works right out of the box