i modified it a little bit. But at least it works like this ...
tablesort
::tablesort(QWidget *parent
){
ui.setupUi(this);
connect(tableView->horizontalHeader(), SIGNAL(sectionClicked(int)),this, SLOT(err()));
db.setDatabaseName("test");
if (!db.
open()) QMessageBox::critical(0,
QObject::tr("Database Error"), db.
lastError().
text());
model->setTable("tbl1");
model->select();
tableView->setSortingEnabled(true);
tableView->setModel(model);
// db.close();
}
void tablesort::err()
{
}
tablesort::tablesort(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
QTableView * tableView = new QTableView(this);
connect(tableView->horizontalHeader(), SIGNAL(sectionClicked(int)),this, SLOT(err()));
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("test");
if (!db.open()) QMessageBox::critical(0, QObject::tr("Database Error"), db.lastError().text());
model = new QSqlTableModel(this);
model->setTable("tbl1");
model->select();
tableView->setSortingEnabled(true);
tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
tableView->setSelectionMode(QAbstractItemView::SingleSelection);
tableView->setModel(model);
// db.close();
}
void tablesort::err()
{
QMessageBox::critical(0, QObject::tr("Database Error"), db.lastError().text());
}
To copy to clipboard, switch view to plain text mode
Bookmarks