Hi
I've a question on sqlite and QSqlDatabase class.
I found the follow example to connect to sqlite db:
In example.cpp file
SqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setHostName("localhost");
db.setDatabaseName("test.db");
if (!db.open()) {
return true;
}
it works but previously I had written the following code:
it compiles and it doesn't show any error by running but it don't open any connection to DBIn example.h file
.......
QSqlDatabase *db;
......
In example.cpp file
b = new QSqlDatabase();
DriverList = db->drivers();
qDebug() << "Driver disponibili: ";
for (int i = 0; i < DriverList.size() ; ++i)
qDebug() << DriverList.at(i);
db->QSqlDatabase::addDatabase("QSQLITE");
db->setHostName("localhost");
db->setDatabaseName("test.db");
if (!db->open()) {
return true;
}
Why???
p.s. sorry for my bad english
Bookmarks