Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlTableModel & QtableView , how to sort by column?
Forum Updated to NodeBB v4.3 + New Features

QSqlTableModel & QtableView , how to sort by column?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 10.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    umen242
    wrote on last edited by
    #1

    Im trying to find what is the easy way to preform sorting on single table im Qurying from SQLite (im using all Qt build class's )
    i have QSqlTableModel delegated (as singletone) class that im setting into QTableview
    like this:
    @ui->PlayList_tableView->resizeColumnsToContents();
    ui->PlayList_tableView->setSortingEnabled(true);
    ui->PlayList_tableView->setAlternatingRowColors(true);
    ui->PlayList_tableView->setModel(PlayListSqlModel::instance()); // this is where i set the model @
    and acurding to this "link ":http://www.qtforum.org/article/26898/how-to-sort-data-by-column-in-a-table-view-model-set-for-table-view-is-qsqlquerymodel-if-click-to-headerview.html
    the sorting suppose to happen automatically , i do see the little sorting triangles in the headers but there is no sorting .
    what im doing wrong here ?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      KillGabio
      wrote on last edited by
      #2

      try using QSortFilterProxyModel

      an example:

      @ QSortFilterProxyModel *sort_filter = new QSortFilterProxyModel(this);
      sort_filter->setSourceModel(model);
      sort_filter->sort (0);
      this->ui->data_table->setModel (sort_filter);
      @

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Castorus
        wrote on last edited by
        #3

        Had the same problem and this worked! Thank you KillGabio.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved