Hello !
I'm trying to use QSqlDataBase with the QSQLITE plugin, but I have a DRIVER NOT LOADED error.
The QSql4.dll is at the root of my soft (a DLL projetc) and I have also create the sqldrivers folder and put the qslite.dll inside.
arbo.jpg
this is my entire class :
SDManagerDataBase.h :
#ifndef SDMANAGERDATABASE_H
#define SDMANAGERDATABASE_H
#include <QObject>
#include <QSqlDataBase>
#include <QSqlQuery>
#include <QVariant>
#include <QSqlError>
#include "SDManagerPreset.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class SDManagerDataBase
: public QObject{
Q_OBJECT
public:
SDManagerDataBase
(QObject *parent
= 0);
~SDManagerDataBase();
int findPresetAssociationByTitle
(QString title
);
bool getPresetById(int id, SDManagerPreset* &preset);
public:
private:
};
#endif // SDMANAGERDATABASE_H
#ifndef SDMANAGERDATABASE_H
#define SDMANAGERDATABASE_H
#include <QObject>
#include <QSqlDataBase>
#include <QSqlQuery>
#include <QVariant>
#include <QSqlError>
#include "SDManagerPreset.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class SDManagerDataBase : public QObject
{
Q_OBJECT
public:
SDManagerDataBase(QObject *parent = 0);
~SDManagerDataBase();
int findPresetAssociationByTitle(QString title);
bool getPresetById(int id, SDManagerPreset* &preset);
public:
private:
QSqlDatabase db;
};
#endif // SDMANAGERDATABASE_H
To copy to clipboard, switch view to plain text mode
SDManagerDataBase.cpp :
#include "SDManagerDataBase.h"
SDManagerDataBase
::SDManagerDataBase(QObject *parent
){
db.setDatabaseName("E:/FSX/Modules/SDManager/SDManager.s3db");
db.open();
}
SDManagerDataBase::~SDManagerDataBase()
{
}
int SDManagerDataBase
::findPresetAssociationByTitle(QString title
) {
int lretour = -1;
QString sql
= "select preset_id from sdsm_presets_associations " "where association_aircraftname = :title";
query.prepare(sql);
query.bindValue(":title", title);
query.exec();
if (query.next())
{
lretour = query.value(0).toInt();
}
return lretour;
}
bool SDManagerDataBase::getPresetById(int id, SDManagerPreset* &preset)
{
QString sql
= "select P.*, S.* from sdsm_presets_stations S, sdsm_presets_list P" "where S.preset_id=P.preset_id AND P.preset_id = :id";
query.prepare(sql);
query.bindValue(":id", id);
query.exec();
if (query.next())
{
preset->gPresetId = query.value(0).toInt();
preset->gPresetName = query.value(3).toString();
SDManagerStation lStation = SDManagerStation(query.value(2).toInt(), query.value(3).toString(), query.value(4).toInt(), query.value(5).toInt());
preset->gPresetStations->append(lStation);
}
return query.size() != -1;
}
#include "SDManagerDataBase.h"
SDManagerDataBase::SDManagerDataBase(QObject *parent)
: QObject(parent)
{
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("E:/FSX/Modules/SDManager/SDManager.s3db");
db.open();
}
SDManagerDataBase::~SDManagerDataBase()
{
}
int SDManagerDataBase::findPresetAssociationByTitle(QString title)
{
int lretour = -1;
QString sql = "select preset_id from sdsm_presets_associations "
"where association_aircraftname = :title";
QSqlQuery query;
query.prepare(sql);
query.bindValue(":title", title);
query.exec();
if (query.next())
{
lretour = query.value(0).toInt();
}
return lretour;
}
bool SDManagerDataBase::getPresetById(int id, SDManagerPreset* &preset)
{
QString sql = "select P.*, S.* from sdsm_presets_stations S, sdsm_presets_list P"
"where S.preset_id=P.preset_id AND P.preset_id = :id";
QSqlQuery query;
query.prepare(sql);
query.bindValue(":id", id);
query.exec();
if (query.next())
{
preset->gPresetId = query.value(0).toInt();
preset->gPresetName = query.value(3).toString();
SDManagerStation lStation = SDManagerStation(query.value(2).toInt(), query.value(3).toString(), query.value(4).toInt(), query.value(5).toInt());
preset->gPresetStations->append(lStation);
}
return query.size() != -1;
}
To copy to clipboard, switch view to plain text mode
This is how a create my SDManagerDataBase object to open a connection :
dB = new SDManagerDataBase();
dB = new SDManagerDataBase();
To copy to clipboard, switch view to plain text mode
If someone can help me ?
Thank you in advance.
Bookmarks