PDA

View Full Version : QSQLITE driver is driving me nuts!



topquarck
29th May 2009, 23:27
hi there;

I have a problem connecting to a sqlite 3.5.9 using QT 4.5 in a fedora 10 machine.
when i try the following code:


db = QSqlDatabase::addDatabase("QSQLITE");
if (db.isValid())
std::cout<<"db is valid!"<<endl;
db.setHostName("localhost");
db.setDatabaseName("feed");
if (db.open()){
std::cout<<"db opened"<<endl;
cout<<"drivers are : "; // just to open all the available drivers
QStringList r = QSqlDatabase::drivers();
for (int i=0;i<r.size();i++)
std::cout<<((QString)r.at(i)).toStdString()<<endl;

QString txt="select * from item_table";
query.exec(txt);
if (query.isValid() && query.isActive()){
std::cout<<"query is valid and active"<<endl;
}
else{
std::cout<<"in error: "<<query.lastError().text().toStdString()<<endl;
}


the output of that code is:



db is valid!
db opened
drivers are : QSQLITE
QSqlQuery::exec: database not open
in error: Driver not loaded Driver not loaded


as you cabn see. both methods : db.isValid() and db.opn() return true. showing the available drivers using QSqlDatabase::drivers() prints QSQLITE

BUT when i try to execute the select statement - on the valid and existing table item_table - it throws to me :"QSqlQuery::exec: database not open"
and the query.lastError().text() prints : "Driver not loaded" twice

what am i missing here??? can anybody help Me PLS??

janus
30th May 2009, 08:52
HI,

what if you try a full path in setDatabaseName()?

Lykurg
30th May 2009, 09:05
Hi, the problem is that you use query without setting the opened database to that query, so the QSqlQuery is invalid. Use

if (db.open())
{
QSqlQuery query;
//...
}

topquarck
30th May 2009, 09:29
Hi, the problem is that you use query without setting the opened database to that query, so the QSqlQuery is invalid. Use

if (db.open())
{
QSqlQuery query;
//...
}


Thanks a lot Sir; the error saying "Driver not Loaded" has disappeared Like Magic

thanks again!