I am trying to create a connection to a database and insert/delete/make queries to the database. I know SQL relatively well but I cannot seem to wrap my head around it in Qt. I used to program in Delphi.
This is my code so far:
QSqlDatabase db;
db.addDatabase("QSQLITE");
db.setHostName( "localhost" ); //I don't know if i should include this the database is in the same directory as my program
db.setDatabaseName( "Xmato.odb" );
db.setUserName( "" ); //There is no username
db.setPassword( "" ); //There is no password
db.open();
db.prepare("SELECT * FROM Members");
db.exec();
I have added this to my .pro file:
QT += sql;
And added this to my main file:
#include <QtSql>
When I run this code I get the error:
QSqlQuery::prepare: database not open
db.lastError().text() returns:
Driver not loaded
Which driver sould I use and what are the drivers?
Any ideas will me much appreciated.
P.S.: I use c++ on Linux Ubuntu 12.04 and use Qt Creator and used LibreOffice Base to create my database.
↧