Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[Solved] QSqlTableModel with two setFilter
void ScooterWindow::UpdateQuery3(const QString &text, const QString &text2)
QString searchitem1 = text;
QString searchitem2 = text2;
ScooterWindow::model->setFilter(QString("name like '%%1%' AND description like '%%2%'").arg(searchitem1).arg(searchitem2)); ScooterWindow::model->select();
Can I separate setFilter queries on two lines?
Do you mean something like
("name like '%%1%' AND "
"description like '%%2%'").arg(searchItem1)
That helps a little bit. I wanted to avoid using "AND". I want to build a query with filter for multiple columns (even more than two in my example) and then the line is not so "stylish" any more.
In that case, you could make a "filter builder"
My target is make filter for all colums of the table. I would probably need 5-6 columns. I have filter for first column in the picture.
@query.exec(QString("SELECT * IN scooter WHERE name like %1%").arg(searchitem));
I would be more confident using this type of query but then my tableView doesn't get updated any more. I have seen examples where multiple WHERE sentences are presented line after line.
Do you have practical example how should I implement this?
I am not sure I am really following you here.
Can you show me the example ?
Sorry about the delay... I moved from a country to another and had to sort things out. I solved the problem like below. It is more or less formatting.
model->setFilter(QString("name like '%%1%' AND "
"type like '%%2%' AND "
"description like '%%3%'")