Redirect PostgreSQL Qt driver stdout/stderr output

356 Views Asked by At

I currently call qInstallMsgHandler() to redirect all Qt Errors, Warnings, and Debug output to my own message handler.

This works 99% of the time but when executing SQL statements through the QSqlQuery object I still get the following output to stderr:

**WARNING:  nonstandard use of \\ in a string literal

LINE 1: EXECUTE qpsqlpstmt_11 ('<?xml version=''1.0'' encoding=''U

HINT:  Use the escape string syntax for backslashes, e.g., E'\\'.**

The database is PostgresSQL version 8.4. Any ideas how I can also intercept and redirect this warning?

2

There are 2 best solutions below

1
hank On BEST ANSWER

It seems that some PostgreSQL library which is being used by the Qt driver writes to stderr.

Yan can redicrect stderr like this:

freopen("my_log.txt", "w", stderr);
0
kh25 On

For others with the same issue you can disable the warning with this code:

QSqlQuery query(db);
query.exec("SET standard_conforming_strings TO true");

But unfortunately this means the problem is hidden from the caller and the backslashes are escaped automatically in the database which may cause problems when retrieving the data later.