0

We are building a static library that is using qDebug and its variants(qWarning,QCritical etc) and custom qDebug message handler. Because of this every qDebugand its variants and its variants are redirected to our message handler. But we don't want to handle application's qDebug and its variants in our message handler. One work around we can do is that passing custom debug message type in the QDebug that we are using inside our static library and checking for this in qMessageHandler callback. But is this safe? Another way we thought of is creating a class that is similar to QDebug and overload stream insertion << operator for every data type same like QDebug does. In Qt 5.2+ we have logging category with which easily can achieve this. But unfortunately we have to use qt 4.7 in our project. Can any one please tell whether there is any easier way to achieve this? Thanks in advance.

Arjuna
  • 697
  • 4
  • 17

1 Answers1

0

Since calling qInstallMessageHandler returns a reference to the original message handler, assuming you use Qt5, you could handle yourself all message type except the ones of type QtDebugMsg where you would call the previous handler.

J-Christophe
  • 1,975
  • 15
  • 13
  • Sorry, I think I need to change the question by qDebug I meant qDebug and all its variants like qWarning, qCritical etc. Also we are not using Qt5.2 in which we can use debug log category. – Arjuna Aug 08 '18 at 10:00
  • @Arjuna in Qt4 must be use http://doc.qt.io/archives/qt-4.8/qtglobal.html#qInstallMsgHandler – eyllanesc Aug 08 '18 at 13:23
  • @eyllanes. Thank you. We are already using it. But the issue is that we want to differentiate whether the call is from our static library or is it from outside. – Arjuna Aug 08 '18 at 14:07
  • @Arjuna okay, I understand, you want to differentiate if it comes from the library or comes from your own application(current). – eyllanesc Aug 08 '18 at 14:13
  • @eyllansec Yes exactly – Arjuna Aug 08 '18 at 14:19