Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
66 lines (53 loc) · 2.27 KB
/
Copy pathmain.cpp
File metadata and controls
66 lines (53 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "Application.h"
#include "sqlite.h"
#include <QMessageBox>
static QString message = QString();
void db4sMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QByteArray localMsg = msg.toLocal8Bit();
// Emulate the default Qt treatment. This might not work in some OS, like Windows.
fprintf(stderr, "%s\n", localMsg.constData());
const char *file = context.file ? context.file : "";
const char *function = context.function ? context.function : "";
localMsg = QString("%1 (%2, %3:%4)\n").arg(msg, function, file).arg(context.line).toLocal8Bit();
// Log using the SQLite log mechanism, so it gets the same treatment than messages
// reported by SQLite itself. This will allow these messages to be seen in our Log window.
// Error code will be the type
sqlite3_log(static_cast<int>(type), localMsg.constData());
}
void boxMessageOutput(QtMsgType, const QMessageLogContext &, const QString &msg)
{
message += msg + "\n";
}
int main( int argc, char ** argv )
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true);
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#endif
#endif
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true);
#endif
#ifdef Q_OS_WIN
// In Windows, there is no output to terminal for a graphical application, so we install
// the output to message box, until the main window is shown or the application exits.
qInstallMessageHandler(boxMessageOutput);
#endif
// Create application object. All the initialisation stuff happens in there
Application a(argc, argv);
// If there has been invocations to the message handler, show it to user in a message box.
if(!message.isEmpty()) {
QMessageBox messageBox;
messageBox.setTextFormat(Qt::RichText);
messageBox.setText("<pre>" + message.toHtmlEscaped() + "</pre>");
messageBox.exec();
}
// Quit application now if user doesn't want to see the UI
if(!a.showMainWindow())
return 0;
qInstallMessageHandler(db4sMessageOutput);
// Run application
return a.exec();
}