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:
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
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;
}
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;
}
To copy to clipboard, switch view to plain text mode
the output of that code is:
db is valid!
db opened
drivers are : QSQLITE
in error: Driver not loaded Driver not loaded
db is valid!
db opened
drivers are : QSQLITE
QSqlQuery::exec: database not open
in error: Driver not loaded Driver not loaded
To copy to clipboard, switch view to plain text mode
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??
Bookmarks