
Originally Posted by
d_stranz
This doesn't matter, and it really is the wrong order to do things. If the model and table view are working together (as the Model/View archtecture says they should) then every time there is a new select(), the table view will automatically be updated because the model will emit a modelReset() or dataChanged() signal. It isn't necessary to tell the table about the model each time you do a select.
Dear d_stranz. I'm not developer, but like read source code. And i known that you are good QT developer.
But try my example and sali555
if (!db.open())
{
QMessageBox::warning(this, tr
("Connection Error"), tr
("Cannot open DB"));
return;
}
m_mainModel->setTable("SPORTOVEC");
if (!m_mainModel->select())
{
QMessageBox::warning(this, tr
("Select Error"), m_mainModel
->lastError
().
databaseText());
return;
}
ui->tableView->setModel(m_mainModel);
if (!db.open())
{
QMessageBox::warning(this, tr("Connection Error"), tr("Cannot open DB"));
return;
}
m_mainModel = new QSqlRelationalTableModel(this, db);
m_mainModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
m_mainModel->setTable("SPORTOVEC");
if (!m_mainModel->select())
{
QMessageBox::warning(this, tr("Select Error"), m_mainModel->lastError().databaseText());
return;
}
ui->tableView->setModel(m_mainModel);
To copy to clipboard, switch view to plain text mode
It's work as sali555 want. Yes, ofcouse. We can use sort filter and other for prepare view column, and then use select statement, but is more easy way use select and then link model with view. In this way view automatically assign all column.
So you should have not empty model to prepare your view.
And sorry my English plz.
Bookmarks