What i want is to load .sqlite file and dimply query in table.
Unfortunately no table is displayed, just empty window.
Database file is in the project main folder.
//db.setDatabaseName(QApplication::applicationDirPath() + QDir::separator() + "faktura.sqlite");
db.setDatabaseName("faktura.sqlite");
db.open();
model->setQuery("SELECT customer_id,name, address FROM customers");
model
->setHeaderData
(0, Qt
::Horizontal,
QObject::tr("Field 1"));
model
->setHeaderData
(1, Qt
::Horizontal,
QObject::tr("Field 2"));
model
->setHeaderData
(2, Qt
::Horizontal,
QObject::tr("Field 3"));
view->setModel(model);
view->show();
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
//db.setDatabaseName(QApplication::applicationDirPath() + QDir::separator() + "faktura.sqlite");
db.setDatabaseName("faktura.sqlite");
db.open();
QSqlQueryModel *model = new QSqlQueryModel;
model->setQuery("SELECT customer_id,name, address FROM customers");
model->setHeaderData(0, Qt::Horizontal, QObject::tr("Field 1"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Field 2"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Field 3"));
QTableView *view = new QTableView;
view->setModel(model);
view->show();
To copy to clipboard, switch view to plain text mode
Bookmarks