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
#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();
}
#include <QtGui/QApplication>
#include "mainwindow.h"
#include "../library/database.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
database myDb;
myDb.createConnection("QSQLITE","../healthdex/resources/recipes.sqlite");
myDb.execute("SELECT * FROM recipe");
myDb.close();
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
for the first try it worked! then after clicking the debug button again
it returned errors
Database Opened
There is an error
QSqlError(-1,
"Driver not loaded",
"Driver not loaded")
Database Opened
QSqlQuery::exec: database not open
There is an error QSqlError(-1, "Driver not loaded", "Driver not loaded")
To copy to clipboard, switch view to plain text mode
i included the files in my project so you can see the 'database' class that i created
healthdex.zip
Added after 27 minutes:
tried adding ..
if(database::querier.exec(query, this->db)){
if(database::querier.exec(query, this->db)){
To copy to clipboard, switch view to plain text mode
and
if(database::querier.exec(query, database::db)){
if(database::querier.exec(query, database::db)){
To copy to clipboard, switch view to plain text mode
in line 26 but it returned 'no matching function for call...'
fixed it by adding
database::querier = QSqlQuery::QSqlQuery(database::db);
To copy to clipboard, switch view to plain text mode
above the
if(database::querier.exec(query)){
if(database::querier.exec(query)){
To copy to clipboard, switch view to plain text mode
Bookmarks