Connect to PostgreSQL database with QtSQL using Connection Service File

312 Views Asked by At

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.

1

There are 1 best solutions below

2
chehrlic On BEST ANSWER

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