PDA

View Full Version : QSqlDataBase + Driver not loaded



Adraesh
22nd November 2012, 13:05
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.

8453

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:
QSqlDatabase db;
};

#endif // SDMANAGERDATABASE_H

SDManagerDataBase.cpp :


#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(QS tring 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;
}

This is how a create my SDManagerDataBase object to open a connection :


dB = new SDManagerDataBase();

If someone can help me ?

Thank you in advance.

amleto
22nd November 2012, 13:58
so it works ok in your build environment, but your problem is when deploying your app on a different machine?

show the directory structure in your new location.

is it

app\
- plugins\
--sqldrivers\
---qsqlite4.dll

?

Adraesh
22nd November 2012, 15:42
Absolutely as u can see :

8454

wysota
22nd November 2012, 16:55
So it's wrong. There should be no "plugins" directory but rather immediately the "sqldrivers" entry with qsqlite dll inside.

Adraesh
22nd November 2012, 17:10
I already tried with no "plugins" directory and immediatly the sqldrivers directory => No change, still the same error : DRIVER NOT LOADED.

wysota
22nd November 2012, 20:53
Make sure you are not mixing debug and release libraries (e.g. having debug Qt libs with a release qsqlite4.dll or vice versa).

Adraesh
22nd November 2012, 22:23
I'm completely lost. I have the right release dll in the right folder or at the root ... I don't know what to do .

amleto
22nd November 2012, 23:53
create a complete and compilable example that contains your problem. And then show us ALL of the information. It's right there in my sig.

Adraesh
23rd November 2012, 07:43
Ok thanks for your answer.

This is a complete and compilable example :

The way is simple :

1 - The external software load the DLL using the DLLStart() method
2 - In the DLLStart() method I create a SDManagerSimConnect object
3 - In the SDManagerSimConnect constructor I open a SimConnect connexion using SimConnect_Open()
4 - Then we arrive in the void SDManagerSimConnect::OnRecvOpen() method
5 - I do my stuff creating some menu etc ... in my external app and when I click on one of my menu created before we arrive in the void SDManagerSimConnect::OnRecvEvent()
6 - In the SDManagerSimConnect::requestPayload() method I just call SimConnect_RequestDataOnSimObjectType()
7 - Then we arrive in the void SDManagerSimConnect::OnRecvSimobjectDataByType()
8 - Now Qt start, I create a SDManagerDataBase object etc ...

SDManager.cpp :

http://pastebin.com/w3a7PT5M

SDManagerSimConnect.h :

http://pastebin.com/WAAgn7Dq

SDManagerSimConnect.cpp :

http://pastebin.com/xPFm4Rnr

SDManagerDataBase.h :

http://pastebin.com/eTadjJQq

SDManagerDataBase.cpp :

http://pastebin.com/qzvkyEqV

Sorry for the pastebin I was obligated to use this because of the caracter lenght restriction.

Sorry for my english and thank you very much.

wysota
23rd November 2012, 09:11
Did you create an instance of QApplication somewhere in your code prior to trying to access the database?

Adraesh
23rd November 2012, 09:46
I don't know where to create the QApplication to not be blocked by the .exec()

wysota
23rd November 2012, 14:02
You don't have to call exec(). It's enough to create the application instance as it is the one loading database drivers.

Adraesh
24th November 2012, 10:54
Hello !

Still the same issue :



DRIVER NAME : QSQLITE
SQL OPEN : 0
SQL ERROR : Driver not loaded Driver not loaded


With this code :



qint32 argc = 1;
char *argv[] = {"SDMANAGER_MAIN"};

QApplication lApplicationFenetre(argc, argv);
lApplicationFenetre.setStyle("plastique");

dB = new SDManagerDataBase();
dB->open();




void SDManagerDataBase::open()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("E:/FSX/Modules/SDManager/SDManager.s3db");
db.open();

QFile file("E:/FSX/Modules/SDManager/SDManager_log.txt");
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
return;

QTextStream out(&file);

out << "DRIVER NAME : " << db.driverName() << endl;
out << "SQL OPEN : " << db.isOpen() << endl;
out << "SQL ERROR : " << db.lastError().text() << endl;
}

wysota
24th November 2012, 13:43
I think the path to the sql drivers is incorrect. Try putting the sqldrivers directory in the same directory as the main binary, not where your dll is located. Alternatively use qt.conf.

Adraesh
24th November 2012, 13:53
What is the main binary ? And where it can be ?

OMG !

It works !

I just create folders :

C:\Qt\4.8.3\plugins\sqldrivers

and IT WORKS !

But I'am obligated to do this when I will produce my application ?

Create all this folders ? like in the main binary ?

wysota
24th November 2012, 14:01
What is the main binary ?
The thing that loads your dll.

amleto
24th November 2012, 16:13
It works !

I just create folders :

C:\Qt\4.8.3\plugins\sqldrivers

and IT WORKS !

But I'am obligated to do this when I will produce my application ?

Create all this folders ? like in the main binary ?

No, you shouldn't need to do that if you deploy your app correctly on other machines.

Adraesh
24th November 2012, 16:15
Yes I know but how can I do to have my sqldrivers folder directly inside the folder application ?