papasmurf1212
14th April 2013, 21:35
I have stored my database in my project folder and made the necessary changes to my .pro file. I currently can open and access the database but it claims that there are no tables. The database, when opened outside of QT, has multiple tables and the queries execute properly. In QT I do the following to run a query:
qDebug() << "Open?" << db.isOpen() << endl;
qDebug() << "isVALID" << db.isValid() << endl;
qDebug() << "SIZE" << db.tables().size() << endl;
QSqlQuery query("SELECT * FROM shifts", db);
if(!query.exec())
{
qDebug() << query.lastError().text();
qDebug() << "ERROR" << endl;
return;
}
while(query.next())
{
QString name = query.value(1).toString();
qDebug() << name << endl;
}
My output says the database is open, valid, and size is 0. Also, the variable db is of type QSqlDatabase and is established in the constructor of my class. Why does it assume the database is empty? Any suggestions on what is going wrong?
qDebug() << "Open?" << db.isOpen() << endl;
qDebug() << "isVALID" << db.isValid() << endl;
qDebug() << "SIZE" << db.tables().size() << endl;
QSqlQuery query("SELECT * FROM shifts", db);
if(!query.exec())
{
qDebug() << query.lastError().text();
qDebug() << "ERROR" << endl;
return;
}
while(query.next())
{
QString name = query.value(1).toString();
qDebug() << name << endl;
}
My output says the database is open, valid, and size is 0. Also, the variable db is of type QSqlDatabase and is established in the constructor of my class. Why does it assume the database is empty? Any suggestions on what is going wrong?