PDA

View Full Version : SQLite problem loading from file and display result in table



unix7777
10th December 2011, 10:30
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.




QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");

//db.setDatabaseName(QApplication::applicationDirPat h() + 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();

Lykurg
10th December 2011, 10:59
what is db.open() returning?

unix7777
13th December 2011, 09:44
Problem solved.Everything wrks fine.All i did is to move the sqlite file in the debug directory.When i start the App from there everything works.