postgresqlqtpyqtqtsql

Connect to PostgreSQL database with QtSQL using Connection Service File


I am using PyQt5 and PostgreSQL 13. My system has a Connection Service File where service "foo" is defined.

How can I connect to that service using Qt SQL?

I found nothing on https://doc.qt.io/qt-5/qsqldatabase.html and https://doc.qt.io/qt-5/sql-driver.html#qpsql

For psycopg2 it would look like conn = psycopg2.connect(service='foo')

An answer for C++ Qt would be fine, it is easy to adapt code to Python.


Solution

  • According to QSqlDatabase::setConnectOptions() you can specify service as a connection option.