Qt World Summit: Register Today!

How to get postgresql errors and messages outside Qt Creator "Application output" pane ?

  • Hi everyone,

    PostgreSQL server send some messages to client on some queries execution.
    Those messages are shown in the "Application Output" pane of Qt Creator.
    I'm trying to get those in my app but I can't figure out how to do this.

    Here is some query to emit such a message :

    @/* plpgsql function declaration */
    RAISE WARNING 'This is a warning';
    $$ LANGUAGE plpgsql;

    /* Function call */
    SELECT * FROM pg_temp.test()@

    Executing this query I get :
    WARNING: This is a warning
    in the "Application Output" pane but either QSqlQuery.lastError() and QSqlDatabase.lastError() returns empty string.

    I've tried to use qInstallMessageHandler. It works for my qDebug() messages but I don't get my psql messages. They are still shown in QtCreator only.

    Does anyone know a possible way to do what I want ?

    I've tested this behavior with Qt 5.3.2 and 5.4

  • I have the same request.
    It looks like qt manage only exceptions not warnings, notices, etc.

  • I read this in the postgresql libpq documentation:

    31.12. Notice Processing
    Notice and warning messages generated by the server are not returned by the query execution functions, since they do not imply failure of the query. Instead they are passed to a notice handling function, and execution continues normally after the handler returns. The default notice handling function prints the message on stderr, but the application can override this behavior by supplying its own handling function.

    So it looks like only exceptions that stops the function executioin get back to the caller, other messages are passed to stderr. So there is no way to handle that messages other than looking at stderr

Log in to reply