0

I have a class MyLogger which shall handle all the logging activities. Therefore I tried to use this example

So my source is :

MyLogger::MyLogger(QWidget *parent) :
  QDialog(parent),
  ui(new Ui::MyLogger)
{
  ui->setupUi(this);

#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
  qInstallMessageHandler(myMessageOutput);
#else
  qInstallMsgHandler(myMessageOutput);
#endif

}

#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
void myMessageOutput(QtMsgType type, const QMessageLogContext &, const QString & str)
{
    const char * msg = str.toStdString().c_str();
#else
void myMessageOutput(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();
    }
}

But then I get a:

Error: 'myMessageOutput' was not declared in this scope
qInstallMessageHandler(myMessageOutput);

Community
  • 1
  • 1
Ralf Wickum
  • 2,850
  • 9
  • 55
  • 103

1 Answers1

1

Either you move myMessageOutput() before MyLogger::MyLogger(), or you use a separate declaration before that.

Tilman Vogel
  • 9,337
  • 4
  • 33
  • 32