QPSQL 驱动未加载 Qt

2021-12-05 00:00:00 postgresql qt c++ qsqldatabase

我在添加数据库时遇到了一些麻烦.

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

调用此方法后出现错误:

QSqlDatabase:未加载 QPSQL 驱动程序QSqlDatabase:可用驱动程序:QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7

我包括到 PATH 变量路径:

PostgreSQL9.3inPostgreSQL9.3libPostgreSQL9.3包括

我也将文件夹 sqldrivers 复制到 Debug 文件夹.还尝试将此文件夹中的 dll 复制到 Debug.也不行.

解决方案

我来这里谷歌搜索是因为我在 Windows 中遇到了同样的问题.

就我而言,为了解决这个问题,我必须为 Windows 32 位安装 PostgreSQL,因为我的 Qt 目标是 MinGW 32 位.

此外,我必须将 PATH 添加到 PostgreSQL bin 和 lib 目录中,以便 Qt 可以找到正确的 .dlls.

@SET PATH=C:Program Files (x86)PostgreSQL9.6in;C:Program Files (x86)PostgreSQL9.6lib;%PATH%

PATH 可以在启动 Qt Creator 之前设置,也可以通过 Projects 窗格中的 Build Environment 使用 Qt Creator 本身.>

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

I include to PATH variable paths to:

PostgreSQL9.3in
PostgreSQL9.3lib
PostgreSQL9.3include

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

解决方案

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

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

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)PostgreSQL9.6in;C:Program Files (x86)PostgreSQL9.6lib;%PATH%

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

相关文章