Hello!
I'm new to Qt and I'm using Qt eclipse integration with version 4.3.4 in Windows XP.
I've created a QTableView in the Eclipse's designer. The tableview is filled with a QSqlTableModel from a SQLite database and I set the sortingEnabled property to true.
When running the program and click in a column header all the table goes empty (the data and the headers)...
This is the code I have:
db.setDatabaseName("stock.sqlite");
if (!db.
open()) QMessageBox::critical(0,
QObject::tr("Database Error"), db.
lastError().
text());
model->setTable("productes");
model->select();
ui.tableView->setSortingEnabled(true);
ui.tableView->setModel(model);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("stock.sqlite");
if (!db.open()) QMessageBox::critical(0, QObject::tr("Database Error"), db.lastError().text());
model = new QSqlTableModel(this);
model->setTable("productes");
model->select();
ui.tableView->setSortingEnabled(true);
ui.tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui.tableView->setSelectionMode(QAbstractItemView::SingleSelection);
ui.tableView->setModel(model);
To copy to clipboard, switch view to plain text mode
What am I doing wrong? I tried a lot of things ( changing the propertys in the designer or after the setModel and I got the same result).
Thanks in advance.
Bookmarks