1 Attachment(s)
[SOLVED] database opened .. database not open
so i was one day programming using Qt
i tried creating a class file name 'database' and added 3 methods
'createConnection', 'execute' and 'close'
in my main.cpp
Code:
#include <QtGui/QApplication>
#include "mainwindow.h"
#include "../library/database.h"
int main(int argc, char *argv[])
{
database myDb;
myDb.createConnection("QSQLITE","../healthdex/resources/recipes.sqlite");
myDb.execute("SELECT * FROM recipe");
myDb.close();
MainWindow w;
w.show();
return a.exec();
}
for the first try it worked! then after clicking the debug button again
it returned errors
Code:
Database Opened
There is an error
QSqlError(-1,
"Driver not loaded",
"Driver not loaded")
i included the files in my project so you can see the 'database' class that i created
Attachment 5981
Added after 27 minutes:
tried adding ..
Code:
if(database::querier.exec(query, this->db)){
and
Code:
if(database::querier.exec(query, database::db)){
in line 26 but it returned 'no matching function for call...'
fixed it by adding
above the
Code:
if(database::querier.exec(query)){
:)
Re: [SOLVED] database opened .. database not open
One needs to use QSqlDatabase::addDatabase() to load the database driver first.