MySQL 无法在 QT 应用程序中连接
我正在开发一个数据库驱动的 QT 项目(基本上是一个日记/日记工具),该项目最终将允许用户连接 MySQL、SQLite 和 Postgres。目前,仅构建了 MYSQL 模块,但我在使其在 Windows 上运行时遇到问题。
我正在 Windows 7 上针对静态构建的 QT 4.7.4 库进行编译,这使得程序能够正确找到 QMYSQL 驱动程序。我知道这一点是因为当我静态构建所有内容时,我没有收到“QMYSQL 驱动程序未加载”错误。但是,当我尝试连接到数据库时,出现“QSqlQuery::exec: 数据库未打开”错误。起初,我认为这是因为远程数据库不接受来自我的地址的连接,但我也无法连接到本地主机(以 root 身份,使用正确的密码)。
我知道应用程序代码很好,因为它在 Linux 上完美运行(相同的 QT 版本,非静态构建......在 Linux 上构建时似乎“正常工作”,无需任何额外的步骤)所以我想知道 QT 是否已构建在 Windows 上正确。我编写了一个批处理文件来自动化构建过程:
TITLE Build QT 4.7.4 (static)
ECHO ON
cd C:\qt-4.7.4\
path C:\MinGW\bin
configure.exe -opensource -platform win32-g++ -release -static -qt-sql-mysql -l mysql -I C:\include -L C:\lib
PAUSE
mingw32-make
PAUSE
我在 Windows 上正确构建 QT 吗?当我第一次遇到这个问题时,我按照以下说明进行操作: http://rag.com.au/linux /qt4howto.html 但在最近的构建后它仍然无法工作。
我必须静态构建 QT,因为如果没有它,我的应用程序将无法找到 QMySQL 驱动程序。起初,我尝试使用 MySQL 5.5 社区版中的包含/库,但由于某种原因构建在中途失败了。 (它不喜欢那个特定的 libmysql.lib 的某些东西)当我尝试使用我在 Linux 中编译的头文件/库时,构建正确完成,但我现在遇到了这个问题。
编译 QT 时头文件/库的存储位置重要吗?
另外,我有一个三核CPU。在 Windows 构建过程中,我注意到 mingw32-make 只使用了一个核心,因为我的 CPU 一直固定在 33%。有没有办法让它使用整个CPU,这样就不会花费4-5个小时来构建?
预先感谢您的任何帮助/建议。
I'm working on a database-driven QT project (basically a journal/diary tool) that will eventually allow users to connect with MySQL, SQLite, and Postgres. For now, only the MYSQL module is built, but i'm having problems making it work on Windows.
I'm compiling against a static-built QT 4.7.4 library on windows 7, and this allowed the program to find the QMYSQL driver properly. I know this because I'm not getting the "QMYSQL driver not loaded" error when I build everything staticly. However, when I try to connect to the database, I get "QSqlQuery::exec: database not open" errors. At first, I thought this was because the remote database wouldn't accept connections from my address, but I couldn't connect to localhost (as root, with the correct password) either.
I know the application code is good because it works perfectly on Linux (Same QT version, non-static build... it seemed to "just work" when built on Linux without any extra steps) so I'm wondering if QT is built correctly on Windows. I wrote a batch file to automate the build process:
TITLE Build QT 4.7.4 (static)
ECHO ON
cd C:\qt-4.7.4\
path C:\MinGW\bin
configure.exe -opensource -platform win32-g++ -release -static -qt-sql-mysql -l mysql -I C:\include -L C:\lib
PAUSE
mingw32-make
PAUSE
Am I building QT correctly on Windows? When I first experienced this problem, I followed these instructions: http://rag.com.au/linux/qt4howto.html but it still wouldn't work after the most recent build.
I had to build QT staticly because without that my application couldn't find the QMySQL driver. At first, I tried using the includes/libraries from the MySQL 5.5 community edition, but the build failed about halfway through for some reason. (It didn't like something about that particular libmysql.lib) When I tried using the headers/libs I compiled against in Linux, the build finished properly, but I'm getting this problem now.
Does it matter where the Headers/Libraries are stored when QT is compiled?
Also, I have a triple-core CPU. During Windows build, I noticed that mingw32-make only used one core since my CPU was pegged at 33% the whole time. Is there a way to make it use the whole CPU so it won't take 4-5 hours to build?
Thanks in advance for any help/suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试此操作来获取适合您的可用驱动程序。
这将为您提供可用驱动程序的列表。
检查“QMYSQL”是否存在。
如果不存在,则必须安装驱动程序。
检查此链接进行安装。
Try this to get the available drivers for you.
This will give you the list of available drivers.
Check whether "QMYSQL" is there or not.
If it is not there, you'll have to install the driver.
Check this link for the installation.