Results 1 to 2 of 2

Thread: QSqlQueryModel+ QTableView+ SQL query with ILIKE

  1. #1
    Join Date
    Dec 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1

    Default QSqlQueryModel+ QTableView+ SQL query with ILIKE

    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.

    Qt Code:
    1. bool TestTableView::eventFilter(QObject *obj, QEvent *event)
    2. {
    3. qDebug() << obj->objectName();
    4.  
    5. return QTableView::eventFilter(obj, event);
    6. }
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Dec 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1

    Default Re: QSqlQueryModel+ QTableView+ SQL query with ILIKE

    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

Similar Threads

  1. Replies: 7
    Last Post: 3rd April 2013, 18:53
  2. Replies: 3
    Last Post: 3rd October 2011, 08:08
  3. Replies: 2
    Last Post: 2nd March 2010, 04:24
  4. SQL transactions with QSqlQueryModel/QTableView
    By estanisgeyer in forum Qt Programming
    Replies: 2
    Last Post: 15th June 2009, 18:52
  5. QTableView/QSqlQueryModel
    By norobro in forum Qt Programming
    Replies: 7
    Last Post: 15th February 2008, 21:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.