Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] qInstallMessageHandler cannot convert parameter 1
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] qInstallMessageHandler cannot convert parameter 1

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 6.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    glararan
    wrote on last edited by
    #1

    Hello,

    I'm using qDebug, but when I release program for other people I want to log when program crash (Beta deploy)
    So I found I can use qInstallMessageHandler for use qDebug.

    But when I add to main qInstallMessaheHandler(LogHandler) it errors with code:
    @error: C2664: 'qInstallMessageHandler' : cannot convert parameter 1 from 'void (__cdecl *)(QtMsgType,QMessageLogContext &,const QString &)' to 'QtMessageHandler'
    None of the functions with this name in scope match the target type@

    main.cpp
    @void LogHandler(QtMsgType type, QMessageLogContext& context, const QString& message)
    {
    QByteArray lMessage = message.toLocal8Bit();

    QString text = NULL;
    
    switch(type)
    {
        case QtDebugMsg:
            text = QString("Debug (%s:%u, %s): %1").arg(context.file).arg(context.line).arg(context.function).arg(lMessage.constData());
            break;
    
        case QtWarningMsg:
            text = QString("Warning (%s:%u, %s): %1").arg(context.file).arg(context.line).arg(context.function).arg(lMessage.constData());
            break;
    
        case QtCriticalMsg:
            text = QString("Critical (%s:%u, %s): %1").arg(context.file).arg(context.line).arg(context.function).arg(lMessage.constData());
    
        case QtFatalMsg:
            text = QString("Fatal (%s:%u, %s): %1").arg(context.file).arg(context.line).arg(context.function).arg(lMessage.constData());
            abort();
    }
    
    QFile file("log.txt");
    file.open(QIODevice::WriteOnly | QIODevice::Append);
    
    QTextStream tStream(&file);
    tStream << text << endl;
    

    }

    int main(int argc, char* argv[])
    {
    QApplication app(argc, argv);

    qInstallMessageHandler(LogHandler);
    
    MainWindow mw;
    mw.showMaximized();
    
    return app.exec&#40;&#41;;
    

    }@

    I tried reintepred_cast, but it crash before app start :D

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      -are you sure your includes are correct and before the definition of your LogHandler()?-

      Your method definition is wrong...you are missing const on the second parameter:
      @
      void LogHandler(QtMsgType type, const QMessageLogContext& context, const QString& message)
      {
      }
      @

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • G Offline
        G Offline
        glararan
        wrote on last edited by
        #3

        Oh thanks, that little mistake :/

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved