qInstallMsgHander identifier not found
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.
Code:
#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
MainWindow theMainWindow;
theMainWindow.show();
return app.exec();
}
Re: qInstallMsgHander identifier not found
I assume you face this problem with Qt5
Quote:
Originally Posted by Qt Docs
Qt::qInstallMsgHandler() is deprecated, so we recommend using Qt::qInstallMessageHandler() instead.
http://qt-project.org/doc/qt-5.0/qtd...rcebreaks.html
Code:
#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
MainWindow theMainWindow;
theMainWindow.show();
return app.exec();
}
Re: qInstallMsgHander identifier not found
It worked. I'll pay more attention next time. Thank you very much.