简体   繁体   English

未加载 QPSQL 驱动程序 Qt

[英]QPSQL driver not loaded 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

I include to PATH variable paths to:我将PATH变量路径包含到:

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

Also I copy folder sqldrivers to Debug folder.我也将文件夹sqldrivers复制到Debug文件夹。 Also tried to copy dlls drom this folder to Debug .还尝试将此文件夹中的 dll 复制到Debug Doesn't work either.也不行。

Add the system variable QT_DEBUG_PLUGINS=1 if you want to get full information of why the QPSQL driver has not been loaded. 如果要获取有关为什么尚未加载QPSQL驱动程序的完整信息,请添加系统变量QT_DEBUG_PLUGINS=1

Probably you will discover that Qt is not able to find it. 可能您会发现Qt找不到它。 Copy and paste the output here to know what exactly happens. 将输出复制并粘贴到此处以了解确切发生的情况。

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 PATH to 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\9.6\bin\;C:\Program Files (x86)\PostgreSQL\9.6\lib\;%PATH%

The PATH can be set before launching Qt Creator or using the Qt Creator itself via the Build Environment in the Projects pane. 可以在启动Qt Creator之前或通过“ Projects窗格中的“ Build Environment使用Qt Creator本身来设置PATH

Use depends.exe on qsqlpsql.dll and found that this dll need libpq.dll from PostgreSQL\\9.3\\lib folder. qsqlpsql.dll上使用depends.exe,发现此dll需要来自PostgreSQL\\9.3\\lib文件夹中的libpq.dll Add libpq.dll to Debug folder and it works:) libpq.dll添加到Debug文件夹,它可以正常工作:)

Try pip install PyQt5 event if you already installed it using conda or installer. 如果您已经使用conda或installer pip install PyQt5事件,请尝试pip install PyQt5事件。 It helped me. 它帮助了我。

I got same problem with deploying Qt application (windeployqt didn't help).我在部署 Qt 应用程序时遇到了同样的问题(windeployqt 没有帮助)。 I had to copy more.dlls (libcrypto-1_1-x64.dll, libiconv-2.dll, libintl-8.dll, libpq.dll, libssl-1_1-x64.dll, libwinpthread-1.dll) from postgreSQL bin path (c:\Program Files\PostgreSQL\12\bin) next to.exe file (according to dependency walker). I had to copy more.dlls (libcrypto-1_1-x64.dll, libiconv-2.dll, libintl-8.dll, libpq.dll, libssl-1_1-x64.dll, libwinpthread-1.dll) from postgreSQL bin path (c:\ Program Files\PostgreSQL\12\bin) 在 .exe 文件旁边(根据 dependency walker)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM