Important: Please read the Qt Code of Conduct -

qInstallMessageHandler() add object method. How?

  • Hello!
    Is there any way to add to qInstallMessageHandler() NOT static function but object method?
    Something like this:

    ObjectType* oObject = new ObjectType();

    I know how to use static method:

    class Class {
      static void  messageHandler(QtMsgType, const QMessageLogContext &, const QString &);

    The question is about calling from object.

  • @bogong
    To answer your question directly, you should be able to go one of:


    But it's not a very good idea! Because if oObject goes away your global message handler is left pointing to a method of a non-existent object....

  • Solution found. Issue closed. Example is here.

  • @bogong
    Having glanced through that, I see it goes


    Which is a static function, exactly what you said you did not want!

    Note that it does not go


Log in to reply