BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
MessageHandler.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file App/MessageHandler.cpp
6 //! @brief Implements function MessageHandler
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #include "App/MessageHandler.h"
16 #include <QMessageBox>
17 #include <iostream>
18 
19 //! This is set by main to be the message handler of our GUI.
20 void MessageHandler(QtMsgType type, const QMessageLogContext&, const QString& msg)
21 {
22  switch (type) {
23  case QtDebugMsg:
24  if (msg.size() == 0) // KDE will pass a zero-length msg qstring
25  break;
26  std::cerr << "DEBUG: " << msg.toStdString() << std::endl;
27  break;
28  case QtInfoMsg:
29  std::cerr << "INFO: " << msg.toStdString() << std::endl;
30  break;
31  case QtWarningMsg:
32  default:
33  if (msg.left(4) == "QXcb")
34  return;
35  std::cerr << "WARNING: " << msg.toStdString() << std::endl;
36  // QMessageBox::warning(QApplication::activeWindow(), qAppName(), msg);
37  break;
38  case QtFatalMsg:
39  std::cerr << "FATAL: " << msg.toStdString() << std::endl;
40  qApp->restoreOverrideCursor();
41  QMessageBox::critical(QApplication::activeWindow(), qAppName(),
42  "Sorry, you encountered a fatal bug.\n"
43  "The application will terminate.\n"
44  "Please note the following and inform the maintainers.\n\n"
45  + msg + "\n");
46  qApp->quit();
47  exit(1);
48  }
49 }
void MessageHandler(QtMsgType type, const QMessageLogContext &, const QString &msg)
This is set by main to be the message handler of our GUI.
Declares function MessageHandler.