QPSQL驱动程序未加载Qt [英] QPSQL driver not loaded Qt

查看:260
本文介绍了QPSQL驱动程序未加载Qt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加数据库时遇到麻烦。

I have some trouble when I want to add a database.

    _dataBase = QSqlDatabase::addDatabase("QPSQL");

调用此方法后出现错误:

After calling this method I have an error:

QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7

我在 PATH 中包含了以下变量的路径:

I include to PATH variable paths to:

PostgreSQL\9.3\bin
PostgreSQL\9.3\lib
PostgreSQL\9.3\include

我也将文件夹 sqldrivers 复制到 Debug 文件夹。还尝试将drom从此文件夹复制到 Debug

Also I copy folder sqldrivers to Debug folder. Also tried to copy dlls drom this folder to Debug. Doesn't work either.

推荐答案

我来这里是因为在Windows中遇到了同样的问题。

I came here googling because I had the same problem in Windows.

要解决此问题,我的Qt目标是MinGW 32位,因此我必须为Windows 32位安装PostgreSQL。

In my case to solve the issue I had to install PostgreSQL for Windows 32 bits since my Qt target was MinGW 32 bits.

另外,我必须将 PATH 添加到PostgreSQL的bin和lib目录中,这样Qt才能找到正确的 .dlls

Additionally, I had to add the PATH to the PostgreSQL bin and lib directories so Qt could find the right .dlls.

@SET PATH=C:\Program Files (x86)\PostgreSQL\9.6\bin\;C:\Program Files (x86)\PostgreSQL\9.6\lib\;%PATH%

PATH 可以在启动Qt Creator之前设置,或者通过 Build Environment 项目窗格。

The PATH can be set before launching Qt Creator or using the Qt Creator itself via the Build Environment in the Projects pane.

这篇关于QPSQL驱动程序未加载Qt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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