Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. qInstallMessageHandler() add object method. How?
Forum Updated to NodeBB v4.3 + New Features

qInstallMessageHandler() add object method. How?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 919 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bogong
    wrote on last edited by
    #1

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

    ObjectType* oObject = new ObjectType();
    qInstallMessageHandler(oObject->objectMethod());
    

    I know how to use static method:

    class Class {
      static void  messageHandler(QtMsgType, const QMessageLogContext &, const QString &);
    };
    
    ...
    qInstallMessageHandler(Class::messageHandler);
    ...
    

    The question is about calling from object.

    JonBJ 1 Reply Last reply
    0
    • B bogong

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

      ObjectType* oObject = new ObjectType();
      qInstallMessageHandler(oObject->objectMethod());
      

      I know how to use static method:

      class Class {
        static void  messageHandler(QtMsgType, const QMessageLogContext &, const QString &);
      };
      
      ...
      qInstallMessageHandler(Class::messageHandler);
      ...
      

      The question is about calling from object.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

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

      qInstallMessageHandler(oObject->objectMethod);
      qInstallMessageHandler(&oObject->objectMethod);
      

      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....

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bogong
        wrote on last edited by
        #3

        Solution found. Issue closed. Example is here.

        JonBJ 1 Reply Last reply
        0
        • B bogong

          Solution found. Issue closed. Example is here.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @bogong
          Having glanced through that, I see it goes

          qInstallMessageHandler(ALogger::mWriteToLog);
          

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

          Note that it does not go

          qInstallMessageHandler(oLogger->mWriteToLog);
          
          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved