Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

Sort by column header in tablemodel

$
0
0
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 sql   greaterThan(QT_MAJOR_VERSION, 4): QT += widgets   TARGET = SQLIte_Login TEMPLATE = app     SOURCES += main.cpp\         login.cpp \   customerinfo.cpp   HEADERS  += login.h\   customerinfo.h   FORMS    += login.ui\   customerinfo.ui   # RC_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());     }

Viewing all articles
Browse latest Browse all 13965

Trending Articles