Results 1 to 18 of 18

Thread: QSqlDataBase + Driver not loaded

  1. #1
    Join Date
    Oct 2012
    Posts
    11

    Default QSqlDataBase + Driver not loaded

    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 :

    Qt Code:
    1. #ifndef SDMANAGERDATABASE_H
    2. #define SDMANAGERDATABASE_H
    3.  
    4. #include <QObject>
    5. #include <QSqlDataBase>
    6. #include <QSqlQuery>
    7. #include <QVariant>
    8. #include <QSqlError>
    9. #include "SDManagerPreset.h"
    10.  
    11. #include <iostream>
    12. #include <string>
    13. #include <fstream>
    14.  
    15. using namespace std;
    16.  
    17. class SDManagerDataBase : public QObject
    18. {
    19. Q_OBJECT
    20.  
    21. public:
    22. SDManagerDataBase(QObject *parent = 0);
    23. ~SDManagerDataBase();
    24.  
    25. int findPresetAssociationByTitle(QString title);
    26. bool getPresetById(int id, SDManagerPreset* &preset);
    27.  
    28. public:
    29.  
    30. private:
    31. };
    32.  
    33. #endif // SDMANAGERDATABASE_H
    To copy to clipboard, switch view to plain text mode 

    SDManagerDataBase.cpp :

    Qt Code:
    1. #include "SDManagerDataBase.h"
    2.  
    3. SDManagerDataBase::SDManagerDataBase(QObject *parent)
    4. : QObject(parent)
    5. {
    6. db = QSqlDatabase::addDatabase("QSQLITE");
    7. db.setDatabaseName("E:/FSX/Modules/SDManager/SDManager.s3db");
    8. db.open();
    9. }
    10.  
    11. SDManagerDataBase::~SDManagerDataBase()
    12. {
    13.  
    14. }
    15.  
    16. int SDManagerDataBase::findPresetAssociationByTitle(QString title)
    17. {
    18. int lretour = -1;
    19.  
    20. QString sql = "select preset_id from sdsm_presets_associations "
    21. "where association_aircraftname = :title";
    22. QSqlQuery query;
    23. query.prepare(sql);
    24. query.bindValue(":title", title);
    25. query.exec();
    26.  
    27. if (query.next())
    28. {
    29. lretour = query.value(0).toInt();
    30. }
    31.  
    32. return lretour;
    33. }
    34.  
    35. bool SDManagerDataBase::getPresetById(int id, SDManagerPreset* &preset)
    36. {
    37. QString sql = "select P.*, S.* from sdsm_presets_stations S, sdsm_presets_list P"
    38. "where S.preset_id=P.preset_id AND P.preset_id = :id";
    39. QSqlQuery query;
    40. query.prepare(sql);
    41. query.bindValue(":id", id);
    42. query.exec();
    43.  
    44. if (query.next())
    45. {
    46. preset->gPresetId = query.value(0).toInt();
    47. preset->gPresetName = query.value(3).toString();
    48.  
    49. SDManagerStation lStation = SDManagerStation(query.value(2).toInt(), query.value(3).toString(), query.value(4).toInt(), query.value(5).toInt());
    50.  
    51. preset->gPresetStations->append(lStation);
    52. }
    53.  
    54. return query.size() != -1;
    55. }
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. dB = new SDManagerDataBase();
    To copy to clipboard, switch view to plain text mode 

    If someone can help me ?

    Thank you in advance.

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlDataBase + Driver not loaded

    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

    ?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Oct 2012
    Posts
    11

    Default Re: QSqlDataBase + Driver not loaded

    Absolutely as u can see :

    arbo.jpg

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlDataBase + Driver not loaded

    So it's wrong. There should be no "plugins" directory but rather immediately the "sqldrivers" entry with qsqlite dll inside.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Oct 2012
    Posts
    11

    Default Re: QSqlDataBase + Driver not loaded

    I already tried with no "plugins" directory and immediatly the sqldrivers directory => No change, still the same error : DRIVER NOT LOADED.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlDataBase + Driver not loaded

    Make sure you are not mixing debug and release libraries (e.g. having debug Qt libs with a release qsqlite4.dll or vice versa).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Oct 2012
    Posts
    11

    Default Re: QSqlDataBase + Driver not loaded

    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 .

  8. #8
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlDataBase + Driver not loaded

    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.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  9. #9
    Join Date
    Oct 2012
    Posts
    11

    Default Re: QSqlDataBase + Driver not loaded

    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.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlDataBase + Driver not loaded

    Did you create an instance of QApplication somewhere in your code prior to trying to access the database?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Oct 2012
    Posts
    11

    Default Re: QSqlDataBase + Driver not loaded

    I don't know where to create the QApplication to not be blocked by the .exec()

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlDataBase + Driver not loaded

    You don't have to call exec(). It's enough to create the application instance as it is the one loading database drivers.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Oct 2012
    Posts
    11

    Default Re: QSqlDataBase + Driver not loaded

    Hello !

    Still the same issue :

    DRIVER NAME : QSQLITE
    SQL OPEN : 0
    SQL ERROR : Driver not loaded Driver not loaded
    With this code :

    Qt Code:
    1. qint32 argc = 1;
    2. char *argv[] = {"SDMANAGER_MAIN"};
    3.  
    4. QApplication lApplicationFenetre(argc, argv);
    5. lApplicationFenetre.setStyle("plastique");
    6.  
    7. dB = new SDManagerDataBase();
    8. dB->open();
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void SDManagerDataBase::open()
    2. {
    3. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    4. db.setDatabaseName("E:/FSX/Modules/SDManager/SDManager.s3db");
    5. db.open();
    6.  
    7. QFile file("E:/FSX/Modules/SDManager/SDManager_log.txt");
    8. if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
    9. return;
    10.  
    11. QTextStream out(&file);
    12.  
    13. out << "DRIVER NAME : " << db.driverName() << endl;
    14. out << "SQL OPEN : " << db.isOpen() << endl;
    15. out << "SQL ERROR : " << db.lastError().text() << endl;
    16. }
    To copy to clipboard, switch view to plain text mode 

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlDataBase + Driver not loaded

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #15
    Join Date
    Oct 2012
    Posts
    11

    Default Re: QSqlDataBase + Driver not loaded

    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 ?

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlDataBase + Driver not loaded

    Quote Originally Posted by Adraesh View Post
    What is the main binary ?
    The thing that loads your dll.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #17
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlDataBase + Driver not loaded

    Quote Originally Posted by Adraesh View Post
    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.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  18. #18
    Join Date
    Oct 2012
    Posts
    11

    Default Re: QSqlDataBase + Driver not loaded

    Yes I know but how can I do to have my sqldrivers folder directly inside the folder application ?

Similar Threads

  1. QSqlDatabase: QMYSQL driver not loaded
    By onder in forum Newbie
    Replies: 12
    Last Post: 29th March 2017, 15:43
  2. QSqlDatabase: QPSQL driver not loaded
    By mistu in forum Qt Programming
    Replies: 0
    Last Post: 18th September 2012, 11:54
  3. Replies: 2
    Last Post: 1st July 2011, 18:56
  4. QSqlDatabase: QODBC driver not loaded
    By sattu in forum Qt Programming
    Replies: 1
    Last Post: 22nd January 2011, 12:40
  5. Need Help:QSqlDatabase: QMYSQL driver not loaded
    By i4ba1 in forum Qt Programming
    Replies: 1
    Last Post: 9th January 2011, 19:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.