PDA

View Full Version : qInstallMsgHander identifier not found



Guett_31
2nd August 2013, 06:32
Hi,

I would like to redirect all the debug message to a file. In order to do so, I call 'qInstallMsgHandler' in the main.cpp to install a message handler that would do the job but the compiler complains and gives me a C3861: 'qInstallMsgHandler': identifier not found error message.

qInstallMsgHandler is declared in the QtGlobal header and QtGlobal is included in my main.ccp, so it should find it. Could someone help me to understand that error, please? Thanks.


#include <QApplication>
#include <QtGui>
#include <QtGlobal>
#include "mainwindow.h"

#define DEBUG_TEST

#ifdef DEBUG_TEST
void crashMessageOutput(QtMsgType type, const char *msg)
{
switch (type)
{
case QtDebugMsg:
fprintf(stderr, "Debug: %s\n", msg);
break;
case QtWarningMsg:
fprintf(stderr, "Warning: %s\n", msg);
break;
case QtCriticalMsg:
fprintf(stderr, "Critical: %s\n", msg);
break;
case QtFatalMsg:
fprintf(stderr, "Fatal: %s\n", msg);
abort();
}
}
#endif

int main(int argc, char *argv[])
{
#ifdef DEBUG_TEST
qInstallMsgHandler(crashMessageOutput);
#endif
QApplication app(argc, argv);
MainWindow theMainWindow;
theMainWindow.show();
return app.exec();
}

Santosh Reddy
2nd August 2013, 15:38
I assume you face this problem with Qt5

Qt::qInstallMsgHandler() is deprecated, so we recommend using Qt::qInstallMessageHandler() instead.

http://qt-project.org/doc/qt-5.0/qtdoc/sourcebreaks.html



#include <QtGui>
#include <QtGlobal>
#include <QApplication>
#include "mainwindow.h"

#define DEBUG_TEST

#ifdef DEBUG_TEST
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
void crashMessageOutput(QtMsgType type, const QMessageLogContext &, const QString & str)
{
const char * msg = str.toStdString().c_str();
#else
void crashMessageOutput(QtMsgType type, const char *msg)
{
#endif
switch (type)
{
case QtDebugMsg:
fprintf(stderr, "Debug: %s\n", msg);
break;
case QtWarningMsg:
fprintf(stderr, "Warning: %s\n", msg);
break;
case QtCriticalMsg:
fprintf(stderr, "Critical: %s\n", msg);
break;
case QtFatalMsg:
fprintf(stderr, "Fatal: %s\n", msg);
abort();
}
}
#endif

int main(int argc, char *argv[])
{
#ifdef DEBUG_TEST
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
qInstallMessageHandler(crashMessageOutput);
#else
qInstallMsgHandler(crashMessageOutput);
#endif
#endif
QApplication app(argc, argv);
MainWindow theMainWindow;
theMainWindow.show();
return app.exec();
}

Guett_31
3rd August 2013, 01:14
It worked. I'll pay more attention next time. Thank you very much.