fulin
27th June 2011, 08:56
Hi,
I created a Qt window form (GUI) and put an empty tableView on the form in Qt Creator. When I started the GUI, the GUI::Initialization() function was called. But nothing happened with the tableView -- no header, no title, no row, no column. It was still empty. Why it did not show up? There was no any error message. What's wrong with my code? Can anybody help me? My code is as the following.
Also how to save the QSqlTableModel contents to a file and load it afterwards from the file?
Thank you in advance.
/Fulin
void GUI::Initialization()
{
QSqlTableModel model;
initializeModel(&model);
tableView_init(&model);
}
void GUI::initializeModel(QSqlTableModel *model)
{
model->setTable("person");
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->select();
model->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("First name"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Last name"));
}
void GUI::tableView_init(QSqlTableModel *model)
{
ui->tableView->setModel(model);
ui->tableView->show();
}
I created a Qt window form (GUI) and put an empty tableView on the form in Qt Creator. When I started the GUI, the GUI::Initialization() function was called. But nothing happened with the tableView -- no header, no title, no row, no column. It was still empty. Why it did not show up? There was no any error message. What's wrong with my code? Can anybody help me? My code is as the following.
Also how to save the QSqlTableModel contents to a file and load it afterwards from the file?
Thank you in advance.
/Fulin
void GUI::Initialization()
{
QSqlTableModel model;
initializeModel(&model);
tableView_init(&model);
}
void GUI::initializeModel(QSqlTableModel *model)
{
model->setTable("person");
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->select();
model->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("First name"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Last name"));
}
void GUI::tableView_init(QSqlTableModel *model)
{
ui->tableView->setModel(model);
ui->tableView->show();
}