Qt & SQLite deploy problems.



  • Hi Guys,

    I have created an application that makes use of the SQLite DB driver however I can only get it to work if I have the directory structure the same as on my dev maching (eg. C:\QtSDK\Desktop\Qt\4.7.3\mingw\plugins\sqldrivers).

    I'm pretty sure I have done something very simple wrong as I have seen this question asked many times.
    So far I have tried the a.addLibraryPath(QCoreApplication::applicationDirPath() + "/plugins/"); (among many other variations) to no joy. I know I am using the correct libraries since it works when putting it in the development dir structure.

    Can anyone suggest what I might be doing wrong?



  • Is the displayed message "driver not loaded driver not loaded"?



  • [quote author="Stavros" date="1311941555"]Is the displayed message "driver not loaded driver not loaded"?[/quote]

    The program (in release mode) is just giving me a seg fault on a vanilla test machine. But I can clear this up be removing the QMessageBox error on the loading of the db. (of course the DB is still not loaded); so technically no error is returned, it just seg faults.

    @
    db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName(dbName);
    if(!db.open()){
    qDebug() << "Couldn't db.open()";
    QMessageBox::critical(0, qApp->tr("Cannot open database"), db.lastError().text(), QMessageBox::Cancel);
    return false;
    }
    @

    [EDIT: fixed code formatting, please use @-tags, not "code", Volker]



  • In your application folder, make a directory namely "sqldrivers" & copy qsqlite.dll file to there. E.g.,
    Applications Folder
    ->YourApp.exe
    -> sqldrivers\qsqlite.dll

    It's work. No need to add library path unless you want to place that file @ specific place



  • [quote author="zither" date="1311954455"]In your application folder, make a directory namely "sqldrivers" & copy qsqlite.dll file to there. E.g.,
    Applications Folder
    ->YourApp.exe
    -> sqldrivers\qsqlite.dll

    It's work. No need to add library path unless you want to place that file @ specific place
    [/quote]

    Hi zither,

    I have already done as you suggested but the database still fails to load. Additionally I am also experiencing a seg fault at the QMessageBox in the code below; are these two errors maybe related, can you see anything I am missing?

    @
    db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName(dbName);
    if(!db.open()){
    qDebug() << "Couldn't db.open()";
    QMessageBox::critical(0, qApp->tr("Cannot open database"),db.lastError().text(), QMessageBox::Cancel);
    }
    @

    I can also confirm that the error is "Driver not loaded Driver not loaded."

    [EDIT: fixed code formatting, please use @-tags, not “code”, Volker]



  • Well, I would make an guess here: ;-)

    Investigate the possibility that the “Driver not loaded Driver not loaded.” and the SEG FAULT are two different problems.



  • [quote author="Stavros" date="1312021044"]Well, I would make an guess here: ;-)

    Investigate the possibility that the “Driver not loaded Driver not loaded.” and the SEG FAULT are two different problems. [/quote]

    Thanks Stavros, my question obviously wasn't clear.
    Could the failure to load the db driver and the subsequent failure of db.open() cause any future calls, such as db.lastError().text(), to result in an access violation?
    I realise this is a separate issue though, which I'll handle once I get the library loaded, I was just wondering at the time of writing the post.



  • To differentiate library can't available or file error, use this code

    @db = QSqlDatabase::addDatabase("QSQLITE");
    if (!db.isDriverAvailable("QSQLITE"))
    QMessageBox::warning(this,"Error",db.lastError().text());@

    If no library in path, error will prompt "Driver not loaded ...".
    Otherwise, that may be file error..



  • Hi Zither,

    I simply get "Driver not loaded." But I know this is the case since if I restore the SDK path it works just fine.
    It simply won't run qsqlite4.dll out of ./plugins/sqldrivers/ nor ./sqldrivers/

    Thanks.



  • Are you sure you copied the correct qsqlite4.dll ?
    There is an incompatible one in QtSDK/QtCreator/bin/sqldrivers and if you are compiling in debug mode, you should probably copy qsqlited4.dll instead of qsqlite4.dll in ./sqldrivers directory.



  • To get information from Qt about the loading of the plugin, you can use the "QT_DEBUG_PLUGINS ":http://doc.qt.nokia.com/latest/deployment-plugins.html environment variable. This might help you to find the cause of the problem. Set this variable to a non-zero value in the environment from which your application is launched.



  • Hi Guys,

    I am still struggling with this problem. Does anyone have any other suggestions?

    I have tried multiple systems and different installs of Mingw & Qt with the same result every time.



  • QT 5.3.1
    Using qsqlite

    I had this same problem and solved with a shotgun approach. I knew it was missing the dll, just didn't know where so I put the dll everywhere, presto it works. Then with the application still running I attempted to delete each of the eight qsqlite.dll files. I could delete 7, one of them was locked. Excellent.

    So it seems that with a deployed application you want to create a "sqldrivers" folder beside the platforms folder and place your sql dll in there. Here is my layout:

    My.exe
    Qt5Core.dll
    Qt5Sql.dll
    +\platforms ( qwindows.dll, qoffscreen.dll, qminimal.dll )
    +\sqldrivers ( qsqlite.dll )

    Cheers All,
    Derrek


  • Moderators

    Thanks for sharing your solution, Derrek. For future reference, the procedure is documented at http://qt-project.org/wiki/Deploy_an_Application_on_Windows (diagram below).

    Note that your program will only use qwindows.dll, so you don't need qofscreen.dll and qminimal.dll.

    !http://i.imgur.com/S582DlV.png(Deployment)!



  • For the record;

    This problem was fixed up by eventually grabbing a later release (think I built from source too).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.