Results 1 to 3 of 3

Thread: Sorting and filtering sql data

  1. #1
    Join Date
    Dec 2010
    Posts
    11
    Thanks
    1

    Default Sorting and filtering sql data

    Hi all,

    how can i sort and filter data in table. I will use sql as source of the data, so i can use where clause as filter, but is there something as data holder (similar to dataadapter, datareader or dataset in .net) which i can operate with, without to fetch the data every time from the sql server?

    Also some reference on sorting filtering would be helpful.

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    99
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Sorting and filtering sql data

    Hi Kode,

    I don' know about dataadapter, datareader or dataset in .net but maybe you could have a look at the following examples.

    models have there own sorting capabilities without using SQL syntax :

    Qt Code:
    1. QSqlRelationalTableModel *model = new SqliteRelationaltableModel(this);
    2. model->setTable("employee");
    3. model->setSort(employee_name, Qt::AscendingOrder);
    To copy to clipboard, switch view to plain text mode 

    QTableView and headers can help you out also :

    Qt Code:
    1. QHeaderView *headerH = tableview->horizontalHeader();
    2. headerH->setMovable(true);//DRAG AND DROP IS POSSIBLE NOW
    3. headerH->setClickable(true);
    4. headerH->setSortIndicator(employee_name,Qt::AscendingOrder);
    5. headerH->setSortIndicatorShown(true);
    6. tableview->setSortingEnabled(true);
    To copy to clipboard, switch view to plain text mode 

    Hope this helps finding more information in the docs.

    Cheers,

    everall

  3. #3
    Join Date
    May 2013
    Posts
    2
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Sorting and filtering sql data

    above that is similar my case..
    i'v tested sorting&filtering on sqlite with qte-4.7.2.
    but Date is not filtered between minimum(1970.1.1) and maximum(2099.12.31). where is wrong point?
    model = new QSqlRelationalTableModel(this);
    model->setTable("albums");
    model->select();

    proxyModel = new MySortFilterProxyModel(this);
    proxyModel->setDynamicSortFilter(true);
    proxyModel->setSourceModel(model);
    ui->tableView->setShowGrid(true);
    ui->tableView->verticalHeader()->hide();
    ui->tableView->setModel(proxyModel);

    void userset_Dialog_32::dateFilterChanged()
    {
    proxyModel->setFilterMinimumDate(ui->fromDateEdit->date());
    proxyModel->setFilterMaximumDate(ui->toDateEdit->date());
    }

    i attached files.
    thanks!
    Attached Files Attached Files

Similar Threads

  1. Key filtering
    By phillip_Qt in forum Qt Programming
    Replies: 2
    Last Post: 24th June 2010, 10:10
  2. Sorting data in QTable
    By sosanjay in forum Qt Programming
    Replies: 4
    Last Post: 27th October 2009, 13:20
  3. sorting Data in QTable
    By sosanjay in forum Qt Programming
    Replies: 6
    Last Post: 24th October 2009, 02:21
  4. Filtering QSqlQueryModel
    By mourad in forum Qt Programming
    Replies: 4
    Last Post: 2nd August 2009, 10:32
  5. Filtering a TreeWidget
    By soul_rebel in forum Qt Programming
    Replies: 6
    Last Post: 26th January 2008, 21:08

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.