qInstallMessageHandler() add object method. How?
Solved
General and Desktop
-
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.
-
@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....