|
12 | 12 | #include <QTimer> |
13 | 13 |
|
14 | 14 | int main(int argc, char* argv[]) { |
15 | | - |
16 | | - QApplication app(argc, argv); |
17 | | - |
18 | | - auto gopts =std::make_shared<GOptions>(argc, argv, gboard::defineOptions()); |
19 | | - auto log = std::make_shared<GLogger>(gopts, SFUNCTION_NAME, GBOARD_LOGGER); |
| 15 | + // Initialize options and logging |
| 16 | + auto gopts = std::make_shared<GOptions>(argc, argv, gboard::defineOptions()); |
| 17 | + auto log = std::make_shared<GLogger>(gopts, SFUNCTION_NAME, GBOARD_LOGGER); |
| 18 | + auto gui = gopts->getSwitch("gui"); |
| 19 | + auto timeout = gopts->getScalarDouble("tt"); |
| 20 | + int ret = EXIT_SUCCESS; |
| 21 | + |
| 22 | + log->info(0, "Starting gboard example..."); |
| 23 | + |
| 24 | + // Optional GUI setup (only if --gui is passed) |
| 25 | + QApplication* app = nullptr; |
| 26 | + QMainWindow* window = nullptr; |
| 27 | + |
| 28 | + if (gui) { |
| 29 | + log->info(0, "gboard", "Running in GUI mode..."); |
| 30 | + app = new QApplication(argc, argv); |
| 31 | + window = new QMainWindow(); |
| 32 | + window->setWindowTitle(QString::fromUtf8("displayUI example")); |
| 33 | + } |
20 | 34 |
|
21 | 35 | auto visManager = new G4VisExecutive; |
22 | 36 | visManager->Initialize(); |
23 | 37 |
|
24 | | - // main window and controls |
25 | | - auto window = new QMainWindow(); |
26 | | - window->setWindowTitle(QString::fromUtf8("displayUI example")); |
27 | | - |
28 | | - auto* gboard = new GBoard(gopts, window); |
29 | | - window->setCentralWidget(gboard); |
30 | | - |
31 | | - auto gui_session = std::make_unique<GUI_Session>(gopts, gboard); |
32 | | - |
33 | | - log->info(0, "gboard example started"); |
34 | | - int ret = EXIT_SUCCESS; |
35 | | - |
36 | | - if (gopts->getSwitch("gui")) { |
| 38 | + // If GUI, show the window and run Qt loop |
| 39 | + if (gui) { |
| 40 | + auto* gboard = new GBoard(gopts, window); |
| 41 | + auto gui_session = std::make_unique<GUI_Session>(gopts, gboard); |
| 42 | + window->setCentralWidget(gboard); |
37 | 43 | window->show(); |
38 | 44 |
|
39 | | - // --- quit after 0.5 s --- |
40 | | - QTimer::singleShot(500, &app, &QCoreApplication::quit); // ⬅️ key line :contentReference[oaicite:0]{index=0} |
| 45 | + // quit after timeout |
| 46 | + QTimer::singleShot(timeout, [] { |
| 47 | + QCoreApplication::quit(); // stop the event loop |
| 48 | + }); |
| 49 | + |
| 50 | + ret = QApplication::exec(); |
41 | 51 |
|
42 | | - ret = QApplication::exec(); // returns when the timer fires |
| 52 | + delete gboard; |
| 53 | + delete window; |
| 54 | + delete app; |
| 55 | + } |
| 56 | + else { |
| 57 | + // CLI mode |
| 58 | + log->info(0, "Running gboard in command line mode..."); |
43 | 59 | } |
44 | 60 |
|
45 | | - delete gboard; |
46 | | - delete window; |
47 | 61 | delete visManager; |
48 | 62 |
|
49 | 63 | return ret; |
50 | | - |
51 | 64 | } |
0 commit comments