|
1 |
| -#include <QString> |
2 |
| -#include <QFile> |
3 |
| -#include <QApplication> |
4 |
| -#include <QDebug> |
5 |
| - |
6 |
| -#include "mainwindow.h" |
7 |
| - |
8 |
| - |
9 |
| -void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) |
10 |
| -{ |
11 |
| - QByteArray localMsg = msg.toLocal8Bit(); |
12 |
| - switch (type) { |
13 |
| - case QtDebugMsg: |
14 |
| - fprintf(stdout, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); |
15 |
| - break; |
16 |
| - case QtInfoMsg: |
17 |
| - fprintf(stdout, "Info: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); |
18 |
| - break; |
19 |
| - case QtWarningMsg: |
20 |
| - fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); |
21 |
| - break; |
22 |
| - case QtCriticalMsg: |
23 |
| - fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); |
24 |
| - break; |
25 |
| - case QtFatalMsg: |
26 |
| - fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); |
27 |
| - abort(); |
28 |
| - } |
29 |
| - |
30 |
| - fflush(stderr); |
31 |
| - fflush(stdout); |
32 |
| -} |
33 |
| - |
34 |
| -int main(int argc, char *argv[]) |
35 |
| -{ |
36 |
| - QApplication a(argc, argv); |
37 |
| - a.setQuitOnLastWindowClosed(true); |
38 |
| - qInstallMessageHandler(myMessageOutput); |
39 |
| - qDebug() << "Message handler test"; |
40 |
| - |
41 |
| - MainWindow mw; |
42 |
| - mw.show(); |
43 |
| - return a.exec(); |
44 |
| -} |
| 1 | +#include <QString> |
| 2 | +#include <QFile> |
| 3 | +#include <QApplication> |
| 4 | +#include <QDebug> |
| 5 | + |
| 6 | +#include <memory> |
| 7 | + |
| 8 | +#include "mainwindow.h" |
| 9 | + |
| 10 | + |
| 11 | +void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) |
| 12 | +{ |
| 13 | + QByteArray localMsg = msg.toLocal8Bit(); |
| 14 | + switch (type) { |
| 15 | + case QtDebugMsg: |
| 16 | + fprintf(stdout, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); |
| 17 | + break; |
| 18 | + case QtInfoMsg: |
| 19 | + fprintf(stdout, "Info: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); |
| 20 | + break; |
| 21 | + case QtWarningMsg: |
| 22 | + fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); |
| 23 | + break; |
| 24 | + case QtCriticalMsg: |
| 25 | + fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); |
| 26 | + break; |
| 27 | + case QtFatalMsg: |
| 28 | + fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); |
| 29 | + abort(); |
| 30 | + } |
| 31 | + |
| 32 | + fflush(stderr); |
| 33 | + fflush(stdout); |
| 34 | +} |
| 35 | + |
| 36 | +int main(int argc, char *argv[]) |
| 37 | +{ |
| 38 | + std::shared_ptr<int> b; |
| 39 | + QApplication a(argc, argv); |
| 40 | + a.setQuitOnLastWindowClosed(true); |
| 41 | + qInstallMessageHandler(myMessageOutput); |
| 42 | + qDebug() << "Message handler test"; |
| 43 | + |
| 44 | + MainWindow mw; |
| 45 | + mw.show(); |
| 46 | + return a.exec(); |
| 47 | +} |
0 commit comments