postgresql QPSQL 驱动未加载 Qt

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26507353/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:39:45  来源:igfitidea点击:

QPSQL driver not loaded Qt

c++qtpostgresqlqsqldatabase

提问by bin-bin

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 PATHvariable paths to:

我包括到PATH变量路径:

PostgreSQL.3\bin
PostgreSQL.3\lib
PostgreSQL.3\include

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

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

采纳答案by Tarod

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

我来这里谷歌搜索是因为我在 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.

在我的情况下,为了解决这个问题,我必须为 Windows 32 位安装 PostgreSQL,因为我的 Qt 目标是 MinGW 32 位。

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

此外,我不得不添加PATH到PostgreSQL bin和lib目录,这样的Qt能找到合适的.dlls

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

The PATHcan be set before launching Qt Creator or using the Qt Creator itself via the Build Environmentin the Projectspane.

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

回答by Antonio Borondo

Add the system variable QT_DEBUG_PLUGINS=1if you want to get full information of why the QPSQLdriver has not been loaded.

QT_DEBUG_PLUGINS=1如果您想获取有关QPSQL未加载驱动程序原因的完整信息,请添加系统变量。

Probably you will discover that Qt is not able to find it. Copy and paste the output here to know what exactly happens.

可能你会发现 Qt 无法找到它。将输出复制并粘贴到此处以了解究竟发生了什么。

回答by bin-bin

Use depends.exe on qsqlpsql.dlland found that this dll need libpq.dllfrom PostgreSQL\9.3\libfolder. Add libpq.dllto Debugfolder and it works:)

使用depends.exe qsqlpsql.dll,发现这个dll需要libpq.dll来自PostgreSQL\9.3\lib文件夹。添加libpq.dllDebug文件夹,它的工作原理:)

回答by user10807076

Try pip install PyQt5event if you already installed it using conda or installer. It helped me.

pip install PyQt5如果您已经使用 conda 或安装程序安装了它,请尝试事件。它帮助了我。