PDA

View Full Version : QSqlQueryModel+ QTableView+ SQL query with ILIKE



rajko
9th June 2012, 13:07
Hi, I have QSqlQueryModel connected with QTableView and it displays data from the table on table view. Now, when the data is displayed in table view I would like to change query ,that is, to reduce displayed set of data with ILIKE sql statement (I'm using Postgres 9.1). For example, SELECT id, description FROM tblCatalouge WHERE description ILIKE %'something'%. There are no other widgets on the form, i would like that string 'something' from the sql query is generated as soon as I start typing and if I press backspace for example that string 'something' is reduced on empty string and that on the table view is displayed full set of data. I thought that considering there is already some basic search in table view predefined I thought that reimplementing eventFilter method of QWidget that holds the table view and intercepting QKeyEvents is a way to go but nothing happens, then I subclassed table view and tried there to reimplement eventFilter method but nothing happens either, it never reach qDebug() in function below. Any suggestions? Thanks in advance.




bool TestTableView::eventFilter(QObject *obj, QEvent *event)
{
qDebug() << obj->objectName();

return QTableView::eventFilter(obj, event);
}



Oh, I'm using Qt 4.8.1, Qt Creator 2.5, win 7 64 bit, Postgres 9.1

rajko
9th June 2012, 23:49
Ok, I solved it, I subclassed QTableView and reimplemented protected void keyPressEvent(QKeyEvent *event) method so that emit signal with string to the slot in the Qwidget where it set model method setQuery. Thanks to the 17 Saturdays viewers by now :)