QtSql应用程序不在部署的机器上工作 [英] QtSql application not working on the deployed machine

查看:188
本文介绍了QtSql应用程序不在部署的机器上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Qt / C ++编写了一个软件。我需要在Windows 7(64位)上部署它,这也是我开发该软件的主机。

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.

问题是我的软件可以与在开发的机器上的sqlite数据库,但是当我尝试部署我的软件在一些其他机器上,它不能与数据库交互。我试图使用以管理员身份运行,但它没有帮助。我也尝试使用兼容模式。

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.

数据库位于本地 C:\Users\username\Desktop\\ \\ db1.sqlite ,因此无需网络或互联网,我的软件就可以正常运行。

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.

我还包括了 QtGui4 QtCore QtSql4 dlls。

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)当您在Windows机器上开发软件时,它的工作方式类似于charm,而不是在已部署软件的机器上,首先要检查的是依赖关系。它们都正常发货吗?

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?

我如何去检查它?那么,这是免费提供的依赖者步行者的目的。你必须在你部署软件的机器上运行;换句话说之后部署。如果它在那里工作,不要在开发机器上运行它。好,这是关于调试,所以让我们得到Qt具体...

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)你正在使用QtSql模块来处理数据库交互在Qt应用。但是,主动态库,又名。 QtSql4.dll是关于抽象的功能。也就是说,所有的Qt代码不处理具体的驱动程序本身。

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.

你可以问为什么这样做?原因是相对直截了当的,因为QtSql模块提供了一个抽象接口,应该可以在不重新构建和重新部署软件的情况下更改数据库存储机制。如果最终用户决定一天使用另一个数据库怎么办?这是不可能的。这是不可能的。

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.

对,我们正在接近一个通用的设计原则,这称为插件架构。 Qt项目有关于它的此处的文档。现在,我们非常接近解决方案,所以让我们进一步到最后。

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)这可能是太长;不读部分:当您部署应用程序时,您将需要让您的最终用户也有插件。这意味着,您需要在这种情况下运送两种类型的sqls,QtSql4.dll以及特定的驱动程序插件。你显然缺少后者。因此,准备发货。但是第二个,对不对? OK,所以你似乎正在使用sqlite和Qt 4,所以你需要得到sqlite的Qt 4驱动程序。

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.

你可以检查Qt SQL数据库驱动程序自己:

You can check the Qt SQL Database drivers here yourself:

SQL数据库驱动程序

根据您所使用的sqlite版本,您有两种选择:

Depending on which sqlite version you are using, you have two options:


QSQLITE2 SQLite版本2

QSQLITE SQLite第3版

基本上,这是你自己如果你必须这样做的方式:

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

一旦你有了这个dll我相信你已经做了,如果你有程序在Windows上已经工作,将 qsqlite4.dll $ QTDIR\plugins\sqldrivers复制到 sqldrivers 目录旁边的可执行文件。它会被自动拿起,然后没有任何麻烦的Qt除非你手动,你应该不应该做的路径。

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)说的是,这是完全通用的方法,所以这将适用于任何SQL类型,如果你替换sqlite所需要的一个。

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.

这篇关于QtSql应用程序不在部署的机器上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆