I realize that after the sorting process by clicking on the header in the tableView, making the data in the table to be inaccurate
example
1 | "Si a"
5 | "Si e"
2 | "Si b"
After click table header and data sorted
1 | "Si a"
2 | "Si b" <- click this row
5 | "Si e"
I still get old data. Still 5 | "Si e", not 2 | "si b"
model->setQuery("select * from almari");
proxyModel->setSourceModel(model);
ui->tableView->setModel(proxyModel);
ui->tableView->setSortingEnabled(TRUE);
model=new QSqlQueryModel();
model->setQuery("select * from almari");
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this);
proxyModel->setSourceModel(model);
ui->tableView->setModel(proxyModel);
ui->tableView->setSortingEnabled(TRUE);
connect(ui->tableView, SIGNAL(pressed(const QModelIndex &)), this, SLOT(clickForEdit(const QModelIndex &)));
To copy to clipboard, switch view to plain text mode
{
int row = index.row();
qDebug() << " ID : " << model->record(row).value("id").toInt();
qDebug() << " Nama : " << model->record(row).value("nama").toString();
}
void Dialog::clickForEdit(const QModelIndex &index)
{
int row = index.row();
qDebug() << " ID : " << model->record(row).value("id").toInt();
qDebug() << " Nama : " << model->record(row).value("nama").toString();
}
To copy to clipboard, switch view to plain text mode
Sorry, my english is bad
Bookmarks