[Qt-interest] launch default QT msgHandler within custom MsgHandler

Stephen Jackson spjackson42 at gmail.com
Mon Apr 12 13:05:34 CEST 2010


On 12 April 2010 10:34, Serge wrote:
> Hello,
>
> i'm using this code:
>
> void myMessageOutput(QtMsgType type, const char *msg)
> {
>        switch (type) {
>        case QtFatalMsg:
> // how to launch here default QT message handler, which would work, if i
> would not used myMessageOutput?
>        }
> }
>
> int main( int argc, char ** argv )
> {
>        qtMsgHandler = qInstallMsgHandler(myMessageOutput);
>

On my first reading of the documentation, I thought that
qInstallMsgHandler would return the address of the default handler,
but in fact it returns 0 when the default handler is in force. If you
had the address of the default handler, you could call it from
myMessageOutput. However, what you can do is (perhaps temporarily)
restore the default handler thus:

void myMessageOutput(QtMsgType type, const char *msg)
{
       switch (type) {
       case QtFatalMsg:
           qInstallMsgHandler(0);
           qFatal(msg); // re- "throw" the message
           // restore handler, although we will in fact have aborted
           qInstallMsgHandler(myMessageOutput);
           break;
       }
}

-- 
HTH,

Stephen Jackson




More information about the Qt-interest-old mailing list