QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
main.cc
Go to the documentation of this file.
1#include "QGCApplication.h"
3#include "LogManager.h"
5#include "Platform.h"
6
7#ifdef QGC_UNITTEST_BUILD
8 #include "UnitTestList.h"
9#endif
10
11QGC_LOGGING_CATEGORY_ON(MainLog, "Main")
12
13int main(int argc, char *argv[])
14{
15 // --- Parse command line arguments ---
16 const auto args = QGCCommandLineParser::parse(argc, argv);
17 if (const auto exitCode = QGCCommandLineParser::handleParseResult(args)) {
18 return *exitCode;
19 }
20
21 // --- Platform initialization ---
22 if (const auto exitCode = Platform::initialize(argc, argv, args)) {
23 return *exitCode;
24 }
25
26 QGCApplication app(argc, argv, args);
27
29
31
32 app.init();
33
34 // Apply after installFilter() (called during app.init) so rules aren't overwritten.
36
37 // --- Run application or tests ---
38 const auto run = [&]() -> int {
41#ifdef QGC_UNITTEST_BUILD
42 case AppMode::ListTests:
43 case AppMode::Test:
44 return QGCUnitTest::handleTestOptions(args);
45#endif
46 case AppMode::BootTest:
47 if (!app.bootTestPassed()) {
48 qCCritical(MainLog) << "Simple boot test failed during GStreamer initialization";
49 return 1;
50 }
51 qCInfo(MainLog) << "Simple boot test completed";
52 return 0;
53 case AppMode::Gui:
54 qCInfo(MainLog) << "Starting application event loop";
55 return app.exec();
56 }
57 Q_UNREACHABLE();
58 };
59
60 const int exitCode = run();
61
62 // --- Cleanup ---
63 app.shutdown();
64
65 qCInfo(MainLog) << "Exiting main";
66
67 // Destroy LogManager while Qt is still fully functional (before static destruction).
68 delete LogManager::instance();
69
70 return exitCode;
71}
#define QGC_LOGGING_CATEGORY_ON(name, categoryStr)
static void applyEnvironmentLogLevel()
static void installHandler()
static LogManager * instance()
Definition LogManager.cc:66
The main application and management class.
void init()
Perform initialize which is common to both normal application running and unit tests.
bool bootTestPassed() const
int main(int argc, char *argv[])
Definition main.cc:13
void setupPostApp()
Complete platform setup after application exists.
Definition Platform.cc:235
std::optional< int > initialize(int argc, char *argv[], const QGCCommandLineParser::CommandLineParseResult &args)
Initialize platform: run safety checks and configure environment.
Definition Platform.cc:160
CommandLineParseResult parse(int argc, char *argv[])
Parse command-line arguments with automatic QCoreApplication management.
AppMode determineAppMode(const CommandLineParseResult &args)
Determine the application mode from parsed arguments.
AppMode
Application execution mode.
std::optional< int > handleParseResult(const CommandLineParseResult &result)
Handle early exit conditions (help, version, error)