qInstallMessageHandler returns the previous handler, that is, by installing handlers and keeping the return value, you can chain them -- what i'm suggesting is basically:

static QtMessageHandler previousMessageHandler;


....

previousMessageHandler = qInstallMessageHandler(messageOutput);

and in here, once you do your appropriate filtering to block debug or whatever, call previousMessageHandler(type, context, str) and let it handle the actual printing part