db.setDatabaseName("test.db");
if (!db.open()) {
QMessageBox::critical(0, qApp
->tr
("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"This example needs SQLite support. Please read "
"the Qt SQL driver documentation for information how "
"to build it.\n\n"
}
query.exec("create table kanji (id int primary key, "
"kanji nvarchar, "
"signification nvarchar)");
query.exec("insert into kanji values(0, '<all>', '0')");
query.exec("insert into kanji values(1, '日', 'Soleil')");
query.exec("insert into kanji values(2, '火', 'Feu')");
query.exec("insert into kanji values(3, '水', 'Eau')");
model->setTable("kanji");
model->select();
model->removeColumn(0);
model->setHeaderData(0, Qt::Horizontal, tr("Kanji"));
model->setHeaderData(1, Qt::Horizontal, tr("Signification"));
view->setModel(model);
view->show();
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("test.db");
if (!db.open()) {
QMessageBox::critical(0, qApp->tr("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"This example needs SQLite support. Please read "
"the Qt SQL driver documentation for information how "
"to build it.\n\n"
"Click Cancel to exit."), QMessageBox::Cancel);
}
QSqlQuery query;
query.exec("create table kanji (id int primary key, "
"kanji nvarchar, "
"signification nvarchar)");
query.exec("insert into kanji values(0, '<all>', '0')");
query.exec("insert into kanji values(1, '日', 'Soleil')");
query.exec("insert into kanji values(2, '火', 'Feu')");
query.exec("insert into kanji values(3, '水', 'Eau')");
QSqlTableModel *model = new QSqlTableModel;
model->setTable("kanji");
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->select();
model->removeColumn(0);
model->setHeaderData(0, Qt::Horizontal, tr("Kanji"));
model->setHeaderData(1, Qt::Horizontal, tr("Signification"));
QTableView *view = new QTableView;
view->setModel(model);
view->show();
To copy to clipboard, switch view to plain text mode
Bookmarks