I am designing Qt log window, So I am using qInstallMsgHandler() function to log all the debug, critical & warning messages on to QTableWidget (in below code I have not implemented It yet). I did as below

Qt Code:
  1. int main(int argc, char *argv[])
  2. {
  3. qInstallMsgHandler(MainWindow::logMessage);
  4. //qInstallMsgHandler(&MainWindow::logMessage); //I tried this also
  5.  
  6. QApplication a(argc, argv);
  7. MainWindow w;
  8. qDebug() << "info message";
  9. qWarning() << "warning message";
  10. qCritical() << "critical message";
  11. w.show();
  12.  
  13. return a.exec();
  14. }
To copy to clipboard, switch view to plain text mode 

MainWindow:

Qt Code:
  1. MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow)
  2. {
  3. ui->setupUi(this);
  4. }
  5.  
  6. MainWindow::~MainWindow()
  7. {
  8. delete ui;
  9. }
  10.  
  11. void MainWindow::logMessage(QtMsgType type, const char *msg)
  12. {
  13. switch (type)
  14. {
  15. case QtDebugMsg:
  16. fprintf(stderr, "Debug: %s\n", msg);
  17. break;
  18. case QtWarningMsg:
  19. fprintf(stderr, "Warning: %s\n", msg);
  20. break;
  21. case QtCriticalMsg:
  22. fprintf(stderr, "Critical: %s\n", msg);
  23. break;
  24. case QtFatalMsg:
  25. fprintf(stderr, "Fatal: %s\n", msg);
  26. abort();
  27. }
  28. }
To copy to clipboard, switch view to plain text mode 

When I compile this code, I am getting below error

Qt Code:
  1. main.cpp:27: error: cannot convert 'void (MainWindow::*)(QtMsgType, const char*)' to 'QtMsgHandler {aka void (*)(QtMsgType, const char*)}' for argument '1' to 'void (* qInstallMsgHandler(QtMsgHandler))(QtMsgType, const char*)'
  2. qInstallMsgHandler(MainWindow::logMessage);
To copy to clipboard, switch view to plain text mode 

Note : If I changed void MainWindow::logMessage(QtMsgType type, const char *msg); this function to static function then it is working fine.
(But if this function is static, I can not create QTableWidgetItem and add them to tableWidget so I want this function to be non static).

And one more issue i am having here, When I use static function, all the messages are printing after I close my application only.

Please let me know What is the issue.

I am using Qt4.8.6 on Windows7

Thanks In Advance.