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 "QGCLogging.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 // --- Run application or tests ---
35 const auto run = [&]() -> int {
38#ifdef QGC_UNITTEST_BUILD
39 case AppMode::ListTests:
40 case AppMode::Test:
41 return QGCUnitTest::handleTestOptions(args);
42#endif
43 case AppMode::BootTest:
44 qCInfo(MainLog) << "Simple boot test completed";
45 return 0;
46 case AppMode::Gui:
47 qCInfo(MainLog) << "Starting application event loop";
48 return app.exec();
49 }
50 Q_UNREACHABLE();
51 };
52
53 const int exitCode = run();
54
55 // --- Cleanup ---
56 app.shutdown();
57
58 qCInfo(MainLog) << "Exiting main";
59 return exitCode;
60}
#define QGC_LOGGING_CATEGORY_ON(name, categoryStr)
void init()
Perform initialize which is common to both normal application running and unit tests.
static void installHandler()
Install Qt message handler to route logs through this class.
Definition QGCLogging.cc:79
int main(int argc, char *argv[])
Definition main.cc:13
void setupPostApp()
Complete platform setup after application exists.
Definition Platform.cc:200
std::optional< int > initialize(int argc, char *argv[], const QGCCommandLineParser::CommandLineParseResult &args)
Initialize platform: run safety checks and configure environment.
Definition Platform.cc:135
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)