I am having a problem making a database connection. I have tried several samples and turtorials to no avail. I am using QT Creator 2.0. I think I might have identified the problem but not sure how to fix it. I have a SQLite database named rider.mt and Iam trying to connect to it. I would eventually create a seperate class for the database operations but I want to get it figured out first. Below is the code and here are my issues:
1. Is this the proper way to access the database?
2. How would I indicate a path if I elect to have the database in a different directory.
3. I get a build error that says QTSql no such file or directory.. I am sure this is the main problem but don't know how to fix it.
#include <QtGui>
#include <QtSql> //*** Error here
#include "dbmain.h"
bool createConnection()
{
db.setDatabaseName("rider.mt");
if (!db.open()) {
db.lastError().text());
return false;
}
return true;
}
int main(int argc, char *argv[])
{
DBMain w;
w.show();
return a.exec();
}
#include <QtGui>
#include <QtSql> //*** Error here
#include "dbmain.h"
bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("rider.mt");
if (!db.open()) {
QMessageBox::warning(0, QObject::tr("Database Error"),
db.lastError().text());
return false;
}
return true;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
DBMain w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Thanks for looking at this!
Bookmarks