I am trying to direct the Qt debugging messages into a text log file. while trying to install the message handler function i have written, the following error occurred:
Qt Code:
  1. main.cpp: error: C3867: 'Log::myMessageHandler': function call missing argument list; use '&Log::myMessageHandler' to create a pointer to member
To copy to clipboard, switch view to plain text mode 
please note that :

1. I have declared the message handler function myMessageHandler as a member function in the singleton Logger class.

2. myMessageHandler function was accessed using the[B] static method ReturnInstance().
3. The function myMessageHandler was installed in the main function of my application using qInstallMessageHanler() function.

The code is as follows:
Qt Code:
  1. /****************************Log.h***********************/
  2. class Log : public QObject
  3. {
  4. Q_OBJECT
  5. public:
  6. //class member declaration
  7.  
  8. static Log& ReturnInstance()
  9. {
  10. static Log Log_obj; //The only Log object that will be used
  11. return Log_obj;
  12. }
  13. void myMessageHandler(QtMsgType type,QMessageLogContext &context,const QString &msg);
  14. private:
  15. //some member variable declartion
  16. QFile m_file;
  17.  
  18. };
  19. /****************************Log.cpp***********************/
  20. //constructor definition
  21. //destructor definition
  22. void Log::myMessageHandler(QtMsgType type, QMessageLogContext &context, const QString &msg)
  23. {
  24.  
  25. QTextStream ostream(&m_file);
  26.  
  27. switch (type) {
  28. case QtDebugMsg:
  29. ostream<<("Debugging Message: %s (%s:%u, %s)\n" , msg, context.file, context.line, context.function);
  30. break;
  31. case QtInfoMsg:
  32. ostream<<("Information Message: %s (%s:%u, %s)\n", msg, context.file, context.line, context.function);
  33. break;
  34. case QtWarningMsg:
  35. ostream<<("Warnning Message: %s (%s:%u, %s)\n" , msg, context.file, context.line, context.function);
  36. break;
  37. case QtFatalMsg:
  38. ostream<<("Fatal Message: %s (%s:%u, %s)\n" , msg, context.file, context.line, context.function);
  39. break;
  40. case QtCriticalMsg:
  41. ostream<<("Critical Message: %s (%s:%u, %s)\n" , msg, context.file, context.line, context.function);
  42. break;
  43. default:
  44. break;
  45. }
  46. }
To copy to clipboard, switch view to plain text mode 
And here is the installation of the message handler function:
Qt Code:
  1. #include "mainwindow.h"
  2. #include <QApplication>
  3. #include "logger.h"
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7. Log::ReturnInstance();
  8. qInstallMessageHandler(Log::ReturnInstance().myMessageHandler); //<------ The error
  9. QApplication a(argc, argv);
  10. MainWindow w;
  11. w.show();
  12.  
  13. return a.exec();
  14. }
To copy to clipboard, switch view to plain text mode