-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
96 lines (87 loc) · 3.55 KB
/
main.cpp
File metadata and controls
96 lines (87 loc) · 3.55 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "mainwindow.h"
#include <QApplication>
#include <stdio.h>
#include <stdlib.h>
#include <QIcon>
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QByteArray localMsg = msg.toLocal8Bit();
switch (type) {
case QtDebugMsg:
fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
case QtInfoMsg:
fprintf(stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
case QtWarningMsg:
fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
case QtCriticalMsg:
fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
case QtFatalMsg:
fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
abort();
}
}
#if 0
void myMessageOutput(QtMsgType type, const QMessageLogContext&, const QString&msg)
{
QByteArray localMsg = msg.toLocal8Bit();
switch (type) {
case QtDebugMsg:
fprintf(stderr, "Debug: %s\n", localMsg.constData());
break;
case QtInfoMsg:
fprintf(stderr, "Info: %s\n", localMsg.constData());
break;
case QtWarningMsg:
fprintf(stderr, "Warning: %s\n", localMsg.constData());
break;
case QtCriticalMsg:
fprintf(stderr, "Critical: %s\n", localMsg.constData());
break;
case QtFatalMsg:
fprintf(stderr, "Fatal: %s\n", localMsg.constData());
abort();
}
}
#endif
int main(int argc, char *argv[])
{
// Set up a custom message handler
qInstallMessageHandler(myMessageOutput);
// Create the application
QApplication a(argc, argv);
// NOTE: Most of the info about this (the application icon), including in
// Qt forums, seems to be out of date. The only scheme that seems to work
// is to put the icns file into resources and associate it with the
// application as here. I have also left it in the .pro file, as instructed
// by Qt, as well as manually adding a reference to it in the plist.info.
// Whether either or both of these is/are actually necessary is unclear.
//
// Later: This only works while the program is actually running. The icon
// that appears in the dock after the program has been closed is the
// default icon, so clearly there is something wrong with the configuration
// that will need to be sorted out.
//
// Still later: the key is to manually delete the generated app bundle,
// rerun qmake, and rebuild (see
// https://stackoverflow.com/questions/4739175/qt-c-on-mac-application-icon-doesnt-set).
// Even this isn't quite enough, actually -- the old icon needs to be
// removed from the dock (trashing it seems safest) so the new one can be
// added.
QApplication::setWindowIcon(QIcon(":/obson.icns"));
QCoreApplication::setOrganizationName("Obson.net");
QCoreApplication::setOrganizationDomain("Obson.net");
QCoreApplication::setApplicationName("MicroSim");
// We want settings to be held in an INI file so we can edit them manually.
// The file will be called MicroSim.ini
QSettings::setDefaultFormat(QSettings::IniFormat);
QSettings settings;
settings.setFallbacksEnabled(false);
MainWindow mainwindow;
//mainwindow.setWindowIcon(QIcon(":/obson.icns"));
mainwindow.show();
return a.exec();
}