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:
main.cpp: error: C3867: 'Log::myMessageHandler': function call missing argument list; use '&Log::myMessageHandler' to create a pointer to member
please note that :
I have declared the message handler function
myMessageHandler
as a member function in the singletonLogger
class.The
myMessageHandler
function was accessed using the static methodReturnInstance()
.The function
myMessageHandler
was installed in the main function of my application usingqInstallMessageHanler()
function.
The code is as follows:
/****************************Log.h***********************/
class Log : public QObject
{
Q_OBJECT
public:
//class member declaration
static Log& ReturnInstance()
{
static Log Log_obj; //The only Log object that will be used
return Log_obj;
}
void myMessageHandler(QtMsgType type,QMessageLogContext &context,const QString &msg);
private:
//some member variable declartion
QFile m_file;
};
/****************************Log.cpp***********************/
//constructor definition
//destructor definition
void Log::myMessageHandler(QtMsgType type, QMessageLogContext &context, const QString &msg)
{
QTextStream ostream(&m_file);
switch (type) {
case QtDebugMsg:
ostream<<("Debugging Message: %s (%s:%u, %s)\n" , msg, context.file, context.line, context.function);
break;
case QtInfoMsg:
ostream<<("Information Message: %s (%s:%u, %s)\n", msg, context.file, context.line, context.function);
break;
case QtWarningMsg:
ostream<<("Warnning Message: %s (%s:%u, %s)\n" , msg, context.file, context.line, context.function);
break;
case QtFatalMsg:
ostream<<("Fatal Message: %s (%s:%u, %s)\n" , msg, context.file, context.line, context.function);
break;
case QtCriticalMsg:
ostream<<("Critical Message: %s (%s:%u, %s)\n" , msg, context.file, context.line, context.function);
break;
default:
break;
}
}
And here is the installation of the message handler function:
#include "mainwindow.h"
#include <QApplication>
#include "logger.h"
int main(int argc, char *argv[])
{
Log::ReturnInstance();
qInstallMessageHandler(Log::ReturnInstance().myMessageHandler); //<------ The error
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}