I am trying to extend the QTableView class to create a table that sorts by column when the column header is clicked. So far the only way I can see to do this is by connecting the QTableView's horizontalHeader's sectionClicked() signal to the QTableView's sortByColumn() slot, but nothing seems to happen when I click the column header other than the sortIndicator changing. How can I get the column to sort, how can I specify how the column should be sorted (ascending vs. descending)?

Here is the constructor for my implementation of QTableView. This is where I am connecting the signal to the slot. I am new to QT so it is quite possible I am doing this completely wrong. Any advice is appreciated.

Qt Code:
  1. MyTableView::MyTableView(QWidget *parent) : QTableView(parent)
  2. {
  3. this->setDragEnabled(false);
  4. this->setAlternatingRowColors(true);
  5. this->setAcceptDrops(false);
  6.  
  7. QHeaderView* rowHeader = this->verticalHeader();
  8. rowHeader->hide();
  9.  
  10. QHeaderView* columnHeader = this->horizontalHeader();
  11. columnHeader->setClickable(true);
  12. columnHeader->setSortIndicatorShown(true);
  13. columnHeader->setSortIndicator(0, Qt::AscendingOrder);
  14.  
  15. QObject::connect(columnHeader, SIGNAL(sectionClicked(int)), this, SLOT(sortByColumn(int)));
  16. }
To copy to clipboard, switch view to plain text mode 

Thanks.