I made a software in Qt/C++. I need to deploy it on Windows 7 (64 bit), which is also the host machine on which I developed the software.
The problem is that my software can interact with the sqlite database on the developed machine, but when I try to deploy my software on some other machine, it can't interact with the database there. I tried to use "Run as Administrator", too, but it did not help. I also tried to use the compatibility mode as well.
The database is located locally at C:\Users\username\Desktop\db1.sqlite
, thus no networking or internet is required for my software to run properly.
I have also included the QtGui4
, QtCore
, and QtSql4
dlls with my software.
Can someone point out what might be going wrong here ?
Right, so there are a couple of things here to be discussed before providing a solution, namely:
1) When you develop software on a Windows machine and it works like a charm, but not on the machines onto which you have deployed your software, the first thing to check is the dependencies. Are they all shipped properly?
How would I go around to check it? Well, that is the purpose of the freely available dependency walker. You have to run on the machine onto which you deployed the software; in other words after the deployment. Do not run it on the development machine if it works there. Good, this is about debugging, so let us get Qt specific...
2) You are using the QtSql module to handle the database interaction which is good in a Qt application. However, the main dynamic library, aka. QtSql4.dll is about the abstracted functionality. That is, all Qt code does not deal with the specific drivers itself.
You could ask that why is it done so? The reason is relatively straight-forward, since the QtSql module provides an abstract interface, it ought to be possible to change the database storage mechanism on the fly without rebuilding and redeploying your software. What if the end user decides to use another database one day? It would not be possible with out this.
Right, we are approaching a generic design principle here which is called Plugin Architecture. The Qt Project has the documentation here about it. Now, we are very close to the solution, so let us get one step further to the end.
3) This could have been the "too long; do not read" part: when you deploy your application, you will need to get your end users to have the plugins, too. That means, you need to ship both types of sqls in this context, the QtSql4.dll as well as the specific driver plugin. You are apparently missing the later. Therefore, prepare for that to be shipped. But what second, right? OK, so you seem to be currently using sqlite and Qt 4, so you will need to get the sqlite Qt 4 driver for that.
You can check the Qt SQL Database drivers here yourself:
Depending on which sqlite version you are using, you have two options:
Basically, this is how you would build the driver yourself if you have to do that:
cd %QTDIR%\src\plugins\sqldrivers\sqlite
qmake "INCLUDEPATH+=C:/SQLITE/INCLUDE" "LIBS+=C:/SQLITE/LIB/SQLITE3.LIB" sqlite.pro
nmake
Once you have that dll, which I am sure you already do if you have the program working on Windows already, copy qsqlite4.dll
$QTDIR\plugins\sqldrivers into a sqldrivers
directory beside your application, the executable. It will be picked up automatically then without any hassle by Qt unless you mess with the paths manually which you ought to not be doing.
4) That being said, this is completely generic an approach, so this will work for any SQL type if you replace sqlite with the one you need.
You should also put qsqlite4.dll
in a directory named sqldrivers
alongside the release version of your application executable.
来源:https://stackoverflow.com/questions/24838245/qtsql-application-not-working-on-the-deployed-machine