I need to pass my certificates to the server.
There's no function in Qt for that because there's no equivalent function in libpq for that either. It happens automatically, as described in Client Certificates inside SSL support from libpq documentation
Excerpt:
If the server requests a trusted client certificate, libpq will send
the certificate stored in file ~/.postgresql/postgresql.crt in the
user's home directory. The certificate must be signed by one of the
certificate authorities (CA) trusted by the server. A matching private
key file ~/.postgresql/postgresql.key must also be present
(in Windows, ~/.postgresql is going to be %APPDATA%\postgresql)
The same will happen for a Qt application since the Qt's QPSQL driver is built on top of libpq. The fact that the connection uses SSL and certificates is essentially transparent even for the driver itself.
EDIT: if ~/.posgresql is not convenient as when they are multiple certificates, alternatives exist:
The location of the certificate and key files can be overridden by the
connection parameters sslcert and sslkey or the environment variables
PGSSLCERT and PGSSLKEY
The connection parameters are set through QSqlDatabase::setConnectOptions. Despite its doc mentioning only an handful of postgresql-specific parameters, it actually will accept any parameter, so anything supported by libpq will work.
QSqlDatabaseis pretty limited - I wouldn't be surprised if there's no way to do this directly.