PDA

View Full Version : QT & SQLite - driver not loaded



Tomasz
20th July 2010, 18:46
Hello!

I'm trying to read from SQLite database. I've wrote simple function:



void MainWindow::odczytajBazeSQL()
{
QSqlDatabase::addDatabase("QSQLITE");

QSqlDatabase bdb;
bdb.setDatabaseName("/test.db");
bdb.open();

QSqlQueryModel *queryModel = new QSqlQueryModel;
queryModel->setQuery("SELECT * FROM t1", bdb);

ui->tableView->setModel(queryModel);
}


test.db is a simple database with one table t1. When I'm trying to read with code above I get error:



QSqlDatabase: QSQLITE driver not loaded
QSqlDatabase: available drivers:
QSqlQuery::exec: database not open


Normally I'm using sqlite3 to create and use databases. What should I do to make it work?

thanks in advance
best regards
Tomasz

wysota
21st July 2010, 00:15
QSqlDatabase: available drivers:
You don't seem to have any Qt sql drivers installed. Maybe you need to install some additional packages for your distribution.

Tomasz
21st July 2010, 09:22
I've copied compilled driver (it wasn't there), I've change my code to:



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

bdb.setDatabaseName("./test.db");
ok = bdb.open();


and now It works fine,

best regards
Tomasz

wysota
21st July 2010, 09:28
Change your code to:

QSqlDatabase bdb = QSqlDatabase::addDatabase("QSQLITE");
bdb.setDatabaseName("/test.db");
bdb.open();

sadjoker
22nd July 2010, 17:13
Hello all. As we are speaking about SQLITE driver i had a very stressful experience with that driver (4.6.2/4.6.3). I deployed over 100 copies of one program using latest sqlite driver. There was no problem anywhere... i put the dll file under the executable file in directory "sqldrivers".
Only in some particular systems this new driver wasn`t loading... i was like O_o. I`m talking about 2% of all the systems.
I`ve spent a lot of hours debugging remotely the machines and didn`t find a way to make it work. But i knew my old software worked on those machines before... then i switched to a sqlite dll from 4.4.0 and .. magically the driver was loaded!
Apparently something in the driver changed but i couldn`t find time to investigate further.

Edit: the machines were WinXP Pro SP3.

wsy2846513
15th June 2014, 11:59
Thank you!!!
The advices really help a lot!!!