Results 1 to 3 of 3

Thread: qInstallMsgHander identifier not found

  1. #1
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    37
    Thanks
    14
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default 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.
    Qt Code:
    1. #include <QApplication>
    2. #include <QtGui>
    3. #include <QtGlobal>
    4. #include "mainwindow.h"
    5.  
    6. #define DEBUG_TEST
    7.  
    8. #ifdef DEBUG_TEST
    9. void crashMessageOutput(QtMsgType type, const char *msg)
    10. {
    11. switch (type)
    12. {
    13. case QtDebugMsg:
    14. fprintf(stderr, "Debug: %s\n", msg);
    15. break;
    16. case QtWarningMsg:
    17. fprintf(stderr, "Warning: %s\n", msg);
    18. break;
    19. case QtCriticalMsg:
    20. fprintf(stderr, "Critical: %s\n", msg);
    21. break;
    22. case QtFatalMsg:
    23. fprintf(stderr, "Fatal: %s\n", msg);
    24. abort();
    25. }
    26. }
    27. #endif
    28.  
    29. int main(int argc, char *argv[])
    30. {
    31. #ifdef DEBUG_TEST
    32. qInstallMsgHandler(crashMessageOutput);
    33. #endif
    34. QApplication app(argc, argv);
    35. MainWindow theMainWindow;
    36. theMainWindow.show();
    37. return app.exec();
    38. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default 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

    Qt Code:
    1. #include <QtGui>
    2. #include <QtGlobal>
    3. #include <QApplication>
    4. #include "mainwindow.h"
    5.  
    6. #define DEBUG_TEST
    7.  
    8. #ifdef DEBUG_TEST
    9. #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
    10. void crashMessageOutput(QtMsgType type, const QMessageLogContext &, const QString & str)
    11. {
    12. const char * msg = str.toStdString().c_str();
    13. #else
    14. void crashMessageOutput(QtMsgType type, const char *msg)
    15. {
    16. #endif
    17. switch (type)
    18. {
    19. case QtDebugMsg:
    20. fprintf(stderr, "Debug: %s\n", msg);
    21. break;
    22. case QtWarningMsg:
    23. fprintf(stderr, "Warning: %s\n", msg);
    24. break;
    25. case QtCriticalMsg:
    26. fprintf(stderr, "Critical: %s\n", msg);
    27. break;
    28. case QtFatalMsg:
    29. fprintf(stderr, "Fatal: %s\n", msg);
    30. abort();
    31. }
    32. }
    33. #endif
    34.  
    35. int main(int argc, char *argv[])
    36. {
    37. #ifdef DEBUG_TEST
    38. #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
    39. qInstallMessageHandler(crashMessageOutput);
    40. #else
    41. qInstallMsgHandler(crashMessageOutput);
    42. #endif
    43. #endif
    44. QApplication app(argc, argv);
    45. MainWindow theMainWindow;
    46. theMainWindow.show();
    47. return app.exec();
    48. }
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. The following user says thank you to Santosh Reddy for this useful post:

    Guett_31 (3rd August 2013)

  4. #3
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    37
    Thanks
    14
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: qInstallMsgHander identifier not found

    It worked. I'll pay more attention next time. Thank you very much.

Similar Threads

  1. Dead method and data identifier
    By RolandHughes in forum Qt Programming
    Replies: 2
    Last Post: 16th May 2013, 03:24
  2. Undeclared Identifier from ui_ header
    By JediSpam in forum Qt Programming
    Replies: 2
    Last Post: 25th August 2011, 16:14
  3. Dynamic objects without identifier...
    By Bill in forum Newbie
    Replies: 7
    Last Post: 18th August 2009, 15:17
  4. please help: "setupUi: identifier not found"
    By rrrrcem in forum Qt Programming
    Replies: 2
    Last Post: 7th July 2008, 09:31
  5. Replies: 3
    Last Post: 27th February 2006, 05:51

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.