0

I have been trying to connect to a remote SQL database with Qt 6.5.2, using QtSql which came included with Qt. The SQLite driver (already installed) won't allow me to connect to a remote SQL database, so I've tried downloading the MySQL and QPSQL drivers which can connect remotely and in both cases it kept giving me the error

QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QPSQL
Error: Could not open database

I have downloaded the qsqlpsql.dll file in the application directory and project directory - as well as in the /plugins/sqldrivers/ folder, but i still have this error. Can someone please help? I have seen other people with the "driver not loaded" error but they usually had compatibility errors, but there is none of that to be seen as far as I'm aware.

P.S. I have also tried downloading on RHEL9 - which is the OS that the sql database is on - but i don't think that is too relevant

1 Answer 1

0

Based on your description, it seems you have not copied the DLLs distributed by Postgres (from the bin\ folder where PostgreSQL is installed) to the folder with your executable. The required DLL are:

  • libpq.dll
  • libssl-1_1-x64.dll
  • libcrypto-1_1-x64.dll
  • libintl-X.dll (X being a number)
  • libiconv-2.dll
  • libwinpthread-1.dll
Sign up to request clarification or add additional context in comments.

6 Comments

Are those files only accessible if I have Postgres downloaded? I don't have it downloaded on my PC - it is on a seperate server and I'm developing on my personal PC. Do I need to download the PostgreSQL on here too? Or is there a repo to get them?
If you don't have a DBA to retrieve the DLLs for you, then you need to download Postgres indeed. I wouldn't trust DLLs downloaded from another source.
I got the following list of libraries: * libpq.dll * zlib1.dll * libcrypto-3-x64.dll * libiconv-2.dll * libintl-9.dll * libssl-3-x64.dll * libwinpthread-1.dll
zlib does not appear to be required but you are right to add libwinpthread (dependency of libintl-9)
I don't know, it seems like there's nothing else besides SQL Server, but it wouldn't start without zlib. I solved it by trial and error, copying all the libraries and gradually deleting and running them. In the end, only these remained.
The question and my answer only cover PSQL, not SQL server and it appears my test application does work without the zlib DLL in the working folder. On another note, you could run the DLLs through the dependency walker instaead of proceeding by trial and error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.