LautaroMed
16th April 2013, 04:26
Hi there! This is my first attempt to use QT and a portable db like SQLite.
I've copied some code from a website to include it in my project, but every time I run it it displays the following message:
"Error initializing database: Driver not loaded Driver not loaded"
Here's my simple code:
QSqlError initDb() {
QSqlQuery q;
QString dataDir = QDesktopServices::storageLocation(QDesktopServices ::DesktopLocation);
QDir dir(dataDir);
QString dbName = dir.filePath("gestion_stock.sqlite");
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(dbName);
if (!db.open()) {
return db.lastError();
}
if (!q.exec(QLatin1String("create table if not exists producto(cod_fabrica varchar(20) primary key, "
"cod_proveedor varchar(20), cod_local varchar(20), stock integer, "
"stock_minimo integer, precio_compra decimal(5), precio_venta decimal(5), "
"proveedor varchar(20), gondola varchar(5), estante integer)"))) {
return q.lastError();
}
return QSqlError();
}
Don't mind the spanish names for the table and fields :P
Any help will be appreciated!
I've copied some code from a website to include it in my project, but every time I run it it displays the following message:
"Error initializing database: Driver not loaded Driver not loaded"
Here's my simple code:
QSqlError initDb() {
QSqlQuery q;
QString dataDir = QDesktopServices::storageLocation(QDesktopServices ::DesktopLocation);
QDir dir(dataDir);
QString dbName = dir.filePath("gestion_stock.sqlite");
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(dbName);
if (!db.open()) {
return db.lastError();
}
if (!q.exec(QLatin1String("create table if not exists producto(cod_fabrica varchar(20) primary key, "
"cod_proveedor varchar(20), cod_local varchar(20), stock integer, "
"stock_minimo integer, precio_compra decimal(5), precio_venta decimal(5), "
"proveedor varchar(20), gondola varchar(5), estante integer)"))) {
return q.lastError();
}
return QSqlError();
}
Don't mind the spanish names for the table and fields :P
Any help will be appreciated!