Results 1 to 3 of 3

Thread: App found qsqlite4.dll driver file but still "Driver not loaded"

  1. #1
    Join Date
    Aug 2011
    Posts
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default App found qsqlite4.dll driver file but still "Driver not loaded"

    Excuse me for my, possible, bad english I have a trouble with including qsqlite driver with my app. I have read a lot about including qsqlite4.dll with package on qtcentre or stackoverflow, but in my situation all of this solutions don't work. I downloaded QtSQK 4.7.3 with QtCreator and wrote a small app with Sqlite usage. I created the "plugins/sqldrivers" dir in my release output folder, found qsqlite4.dll (478720 bytes - in "/mingw/plugins/sqldrivers" folder), put it into the "plugins/sqldrivers" dir. Added the
    Qt Code:
    1. a.addLibraryPath(a.applicationDirPath()+"/plugins");
    To copy to clipboard, switch view to plain text mode 
    into main.cpp. After this i saw that
    Qt Code:
    1. qDebug() << a.libraryPaths(); //where a is QApplication
    To copy to clipboard, switch view to plain text mode 
    will output "("app/release/plugins", "C:/QtSDK/Desktop/Qt/4.7.3/mingw/plugins", "app/release")", and through Resource Monitor in Win7 i see that qsqlite4.dll loaded when my app start and work fine with SQL. Then, i want to check, will it work on clear system without QT. If i rename the "C:/QtSDK/Desktop/Qt/4.7.3/mingw/plugins" to some like "plugins__", i see, that my app have only 2 paths - "..../release/plugins" and "..../release". In all that situations my QSqlDatabase found the QSQLITE driver -
    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    2. db.drivers()
    To copy to clipboard, switch view to plain text mode 
    will output "QSQLITE". But, when i try to use qsqlite4.dll from my app bundle, i got a error from QSqlDatabase "Driver not loaded Driver not loaded". If i remove qsqlite4.dll from "myapp/plugins/sqldrivers" dir QSqlDatabase will not found them (db.drivers() return nothing), so i think i have a situation when driver DLL is founded by my app, but does not load. Why?

    Trying not to use "app/plugins/sqldrivers/qsqlite4.dll" dir but use "app/sqldrivers/qsqlite4.dll" instead without adding a libraryPath does nothing, QSqlDatabase even does not found the driver and return nothing with db.drivers()..

    It's like:
    1.
    app/plugins/sqldrivers/qsqlite4.dll
    QtSDK/Desktop/Qt/4.7.3/mingw/plugins/sqldrivers/qsqlite4.dll - app use this file, all fine

    2. app/plugins/sqldrivers/qsqlite4.dll - driver found, not loaded (with adding libraryPath "plugins");

    3. app/sqldrivers/qsqlite.dll - driver not found, not loaded

    In advance thank you all for the information..

  2. #2
    Join Date
    Aug 2011
    Posts
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: App found qsqlite4.dll driver file but still "Driver not loaded"

    After hours of dance with tambourine i found a solution: in my project the QSqlDatabase definition is in MainWindow class before MainWindow initialization (for class scope), and apparently the qsqlite4.dll does not initialized before that step. I do not understand why this don't happened when i used "QTDIR/mingw/plugins" (by default) as plugins folder, but when i rewrite QSqlDatabase initialization it work fine with deployment dll.

    Old, work fine only with QTDIR/mingw/plugins:
    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    2. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
    3. {
    4. }
    To copy to clipboard, switch view to plain text mode 

    New, work fine with deployment dll:
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
    2. {
    3. db = db.addDatabase("QSQLITE");
    4. }
    To copy to clipboard, switch view to plain text mode 

    Be careful not to repeat my mistakes

  3. The following user says thank you to merelendor for this useful post:

    Mobility (8th April 2013)

  4. #3
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: App found qsqlite4.dll driver file but still "Driver not loaded"

    You should never store the QSqlDatabase object anywhere. Use the static functions to the the database on a local variable and let it go out of scope. Use of global is not recommended.

Similar Threads

  1. got error message "driver not loaded"
    By rivci in forum Newbie
    Replies: 2
    Last Post: 13th January 2011, 10:37
  2. run time error "driver not loaded" for sqlite.
    By netmat in forum Qt Programming
    Replies: 0
    Last Post: 2nd August 2010, 06:42
  3. Replies: 1
    Last Post: 24th April 2010, 04:43
  4. Replies: 4
    Last Post: 10th November 2009, 20:48
  5. The strange problem:"QSqlDatabase: QMYSQL driver not loaded"
    By osmanthus in forum Installation and Deployment
    Replies: 2
    Last Post: 22nd January 2009, 16:12

Tags for this Thread

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.