13

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:

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

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

bin-bin
  • 532
  • 2
  • 6
  • 16
  • Maybe use depends.exe on the psql driver to verify that it is pulling in the dlls that you have in PostgreSQL\9.3\bin – drescherjm Oct 22 '14 at 12:37
  • @drescherjm Thanks for reply:) I found that qsqlpsql.dll need libpq.dll from PostgreSQL\9.3\lib folder. I add this dll to Debug folder and now error message has gone:))) Many thanks:)) – bin-bin Oct 24 '14 at 06:53

5 Answers5

12

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

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

Tarod
  • 6,732
  • 5
  • 44
  • 50
12

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)\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.

Tarod
  • 6,732
  • 5
  • 44
  • 50
3

Use depends.exe on qsqlpsql.dll and found that this dll need libpq.dll from PostgreSQL\9.3\libfolder. Add libpq.dll to Debug folder and it works:)

bin-bin
  • 532
  • 2
  • 6
  • 16
0

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

Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
0

I got same problem with deploying Qt application (windeployqt didn't help). 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).