PDA

View Full Version : SQLite Out of Memory error



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!

ChrisW67
16th April 2013, 06:43
In order to use a Sqlite database your program must have access to the QSqlite plugin, which is not available to your program as the error message indicates. Running inside a normal IDE, where Qt is installed, this should be available. If this program is deployed then you must deploy the relevant plugins (sqldrivers folder) along with the Qt libraries.

BTW: Why do you think

"Error initializing database: Driver not loaded Driver not loaded"
has anything to do with your thread title?

SQLite Out of Memory error

LautaroMed
16th April 2013, 15:27
I forgot to change that, at first it said "Out of memory: sqlite something" then it changed to driver not loaded.

I have no idea how to do that, I'm running QtCreator.

If I build the "Books Demonstration" example, which uses SQLite, it works just fine.