Sort by column header in tablemodel
-
wrote on 20 Jan 2014, 21:04 last edited by
I've checked the forums and documentation but still can't seem to get it to work. Supposed to be essentially "automatic" and "built-in" using one line of code but the sort function just doesn't happen. The arrow indicators do show up but that's all that happens.
Thank you for your help.
Here's the code:
SQLite_Login.Pro
@
QT += core gui sqlgreaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = SQLIte_Login
TEMPLATE = appSOURCES += main.cpp
login.cpp
customerinfo.cppHEADERS += login.h
customerinfo.hFORMS += login.ui
customerinfo.uiRC_FILE = nhx.rc@
main.cpp
@#include "login.h"
#include <QApplication>int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Login w;
w.show();return a.exec();
}@
customerinfo.cpp
@
#include "customerinfo.h"
#include "ui_customerinfo.h"
#include<QMessageBox>#include <QDesktopServices>
#include <QUrl>#include <QFileDialog>
#include <QString>
void CustomerInfo::on_pushButton_Load_Tbl_clicked()
{
Login conn;
QSqlQueryModel * modal=new QSqlQueryModel();conn.connOpen();
QSqlQuery* qry=new QSqlQuery(conn.mydb);qry->prepare("SELECT LotNo, UserName, LastName, Role from Test_LOGIN order by LotNo ");
qry->exec();
modal->setQuery(*qry);
ui->tableView->setModel(modal);ui->tableView->setSortingEnabled(true); ui->tableView->sortByColumn(true);
conn.connClose();
qDebug()<<(modal->rowCount());}@
-
wrote on 21 Jan 2014, 08:48 last edited by
nHx4U,
I can not understand what is your problem is. If you can clarify more, I by myself or someone can try to help you.
-
wrote on 21 Jan 2014, 16:00 last edited by
Hi.
Thanks for the reply.
I can load data from a SQLite table in a TableView on a gui form. The problem is that you are supposed to be able to re-sort the table by clicking on the column headers. To toggle from ascending to descending.
The sort direction triangles (up/down arrows) show up in the header but clicking on it does not re-sort the table.
1/3