{"id":23624749,"url":"https://github.com/hcl-tech-software/qt-traffic-light","last_synced_at":"2026-01-02T10:45:34.045Z","repository":{"id":212423819,"uuid":"553741235","full_name":"HCL-TECH-SOFTWARE/qt-traffic-light","owner":"HCL-TECH-SOFTWARE","description":"A sample application showing how to use code generated by DevOps Model/Code RealTime in a Qt UI application.","archived":false,"fork":false,"pushed_at":"2024-09-10T04:38:31.000Z","size":113,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-08-29T12:45:02.588Z","etag":null,"topics":["code-realtime","model-realtime"],"latest_commit_sha":null,"homepage":"https://www.hcl-software.com/devops-model-realtime","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HCL-TECH-SOFTWARE.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-18T17:37:11.000Z","updated_at":"2025-06-08T05:45:45.000Z","dependencies_parsed_at":"2023-12-14T07:28:03.837Z","dependency_job_id":"d4f8d5ae-8793-4dad-a6cd-e2a2d031fbe9","html_url":"https://github.com/HCL-TECH-SOFTWARE/qt-traffic-light","commit_stats":null,"previous_names":["hcl-tech-software/qt-traffic-light"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/HCL-TECH-SOFTWARE/qt-traffic-light","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HCL-TECH-SOFTWARE%2Fqt-traffic-light","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HCL-TECH-SOFTWARE%2Fqt-traffic-light/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HCL-TECH-SOFTWARE%2Fqt-traffic-light/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HCL-TECH-SOFTWARE%2Fqt-traffic-light/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HCL-TECH-SOFTWARE","download_url":"https://codeload.github.com/HCL-TECH-SOFTWARE/qt-traffic-light/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HCL-TECH-SOFTWARE%2Fqt-traffic-light/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272926172,"owners_count":25016423,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-30T02:00:09.474Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-realtime","model-realtime"],"created_at":"2024-12-27T21:16:21.350Z","updated_at":"2026-01-02T10:45:33.976Z","avatar_url":"https://github.com/HCL-TECH-SOFTWARE.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# qt-traffic-light\nThis sample shows how a user interface implemented in Qt can be used for a realtime application developed with [DevOps Model RealTime](https://model-realtime.hcldoc.com/help/index.jsp) or [DevOps Code RealTime](https://secure-dev-ops.github.io/code-realtime/).\n\nThe sample is a variant of https://github.com/HCL-TECH-SOFTWARE/traffic-light-web which uses a web page as the user interface for a traffic light application. Here the web page has been replaced with a Qt UI based on the following sample from the Qt documentation:\n\nhttps://doc.qt.io/qt-6/qtstatemachine-trafficlight-example.html\n\nThe state machine logic of this Qt sample was removed and replaced with the code generated from Model RealTime or Code RealTime.\n\n### Building the sample\nTo build the sample you need to have Qt and a C++ toolchain installed. The sample is configured for Qt 6.7 on Windows, using the MinGw toolchain, but you can change this if you have another platform or toolchain. You also need to have either [Model RealTime](https://model-realtime.hcldoc.com/help/index.jsp) installed on Eclipse OR [Code RealTime](https://secure-dev-ops.github.io/code-realtime/) installed on Visual Studio Code or Eclipse Theia.\n\n1. **Generate the realtime part of the application**\n    \n    a. If you want to use Model RealTime, open the [Model RealTime project](https://github.com/HCL-TECH-SOFTWARE/qt-traffic-light/tree/main/TrafficLightsDemo). Right-click on the TC `app_mingw.tcjs` and perform the command `Generate Code`.\n    \n    b. If you want to use Code RealTime, open the [Code RealTime workspace folder](https://github.com/secure-dev-ops/code-realtime/tree/main/art-samples/QtTrafficLight). Set the TC `app.tcjs` as active so that code gets generated for it.\n2. **Set-up the Qt project**\n   \n   Open the Qt project [QTTrafficLight.pro](https://github.com/HCL-TECH-SOFTWARE/qt-traffic-light/tree/main/QTTrafficLight/QTTrafficLight.pro) in a text editor. Set the `TARGET_RTS_LOCATION` variable to the location of the TargetRTS to use (located inside the Model RealTime or Code RealTime installations). Also set the `TARGET_FOLDER` variable to the location where generated code from Model RealTime or Code RealTime was placed. For Code RealTime you also must set the `SOURCE_FOLDER` variable since it uses a hand-written header file which is located in the `include` subfolder.\n\n3. **Build the application from Qt Creator**\n   \n   Open the Qt project [QTTrafficLight.pro](https://github.com/HCL-TECH-SOFTWARE/qt-traffic-light/tree/main/QTTrafficLight/QTTrafficLight.pro) in Qt Creator and build it (using a command from the Build menu).\t\n\n### How the application works\nWe choose to let the main thread run the Qt UI. In `main.cpp` the QApplication is created with a main window. The main thread will then simply run the application’s event loop which handles all Qt UI events.\n\nIn the main window constructor (`MainWindow.cpp`) we create a QThread (`MyThread.cpp`) responsible for running the realtime part of the application. We use Qt signals and slots as the means of communicating messages from the realtime code to the Qt UI.\n\nWhen the QThread starts to run (function `MyThread::run()`) it will call `RTMain::entryPoint()` and then pass necessary arguments which otherwise is provided by the TargetRTS. In the sample these are the path to the Qt application and “-URTS_DEBUG=quit” (to not use the model debugger). If you launch the Qt application with command-line arguments, these are passed to the TargetRTS. For example, to launch so that you can attach the model debugger to the application, use the `obslisten=\u003cport\u003e` argument.\n\nThe realtime part of the application is run by `MyThread` and uses a top capsule `TLSystem` with these capsule parts:\n#### trafficLight\nImplements the traffic light logic using a state machine. This part is independent of Qt.\n#### pedLight\nImplements the pedestrian light logic using a state machine. This part is independent of Qt.\n#### qtUI\nResponsible for communication from the realtime part of the application to the Qt UI. When events arrive from `trafficLight` or `pedLight`, the Qt application is notified by emitting the signals that were mapped in the `MainWindow` constructor. The mapped slot functions will then update the Qt UI as required.\n#### pushButton\nResponsible for communication from the Qt UI to the realtime part of the application. It uses an external port as the mechanism to allow the Qt main UI thread to inject an event when the user pushes the button in the Qt UI. Note that after each injected event the external port has to be enabled again to allow the button to be pushed another time.\nThe Qt UI needs access to the `PushButton` capsule so it can inject the event. In the sample this works by letting the `PushButton` state machine’s initial transition register the capsule instance with the `MyThread`. \n\nNote that the sample skips the start-up synchronization that typically is necessary for a real application. It may take some time for the realtime part of the application to start-up and during that time the Qt UI should not send messages to it. One typical solution would be to let the realtime part of the application notify the Qt UI with a signal when it is ready to start accepting events.\n\n### How the Qt project was created\nFor reference, the QTTrafficLight project was created using the following steps:\n1.\tOpen Qt Creator\n2.\tCreate a new project (**File - New Project**)\n3.\tChoose the template `Qt Widgets Application` in the New Project dialog. Click the **Choose...** button.\n4.\tGive the project a name (QTtrafficLight) and set the file location and then press **Next**\n5.\tSelect build system `qmake` and press **Next**\n6.\tUncheck **Generate form** on the Details page and press **Next**\n7.\tSkip over the Translation page by pressing **Next**\n8.\tOn the Kits page select `Desktop QT 6.7.0 MinGW 64-bit` and press **Next**\n9.\tOn the Summary page press **Finish**\n10.\tThere are two static TargetRTS libs `libObjecTime.a` and `libObjecTimeTypes.a` present in the Model/Code RealTime installation at this location: \n\n```\nTargetRTS/lib/WinT.x64-MinGw-12.2.0\n```\n\nThere are also two TargetRTS include folders:\n\n```\nTargetRTS/include\nTargetRTS/target/WinT\n```\n\nWe have to add the TargetRTS interfaces from these paths while adding TargetRTS libs. We have to add both libs one by one by selecting first path for first lib and second path for second lib.\n\nNow right click on the QTTrafficLight project and select **Add Library…**. One popup window will appear. Select **External library** and press **Next**. \n\nClick the **Browse** buttons to locate the library file and include path (mentioned above). \n\n11.\tAdd Windows socket library by editing the QTTrafficLight.pro file in a text editor:\n\n```\nLIBS += -lwsock32\n```\n\n12.\tNow right click on the QTTrafficLight project and select **Add Existing Directory...**. Click **Browse** to locate the source code generated by Model/Code RealTime. Press **Start Parsing** and select only the generated .h/.cpp files.\n13.\tAdd the path for generated .h/.cpp files in .pro file.\n\n```\nINCLUDEPATH += $${TARGET_FOLDER}\n```\n\nNote that to make the Qt project work with both Model RealTime and Code RealTime the variables `TARGET_RTS_LOCATION` and `TARGET_FOLDER` were introduced and hard-coded paths were updated to use these variables instead.\n\n### Project deployment and using the Model Debugger\nTo run the Qt application from the command-line we first have to deploy it using the `windeployqt.exe` utility. When using MinGw the path to this utility will be at a location similar to:\n\n```\nC:\\QT\\6.7.0\\mingw_64\\bin\u003ewindeployqt.exe\n```\n\nTo run `QTTrafficLight.exe` from the command-line, copy the executable created by the Qt Creator IDE into a separate folder. Then run `windeployqt` with the path to the executable as argument. For example:\n\n```\ncd  C:\\QT\\6.7.0\\mingw_64\\bin\n\nC:\\QT\\6.7.0\\mingw_64\\bin\u003ewindeployqt.exe C:\\Executablefile\\QTTrafficLight.exe\n```\n\nAll files needed to run QTTrafficLight.exe from the command prompt will be created in the Executablefile folder.\n\nNow we can start the Qt application with the flag that lets the Model Debugger attach to it:\n\n```\nC:\\Executablefile\u003eQTTrafficLight.exe -obslisten=12345\n```\n\nYou may replace the port number with something that is available on your machine.\n\nFor more information about the Model Debugger, see [the documentation](https://model-realtime.hcldoc.com/help/topic/com.ibm.xtools.rsarte.webdoc/Articles/Running%20and%20debugging/index.html?cp=23_2_13).\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhcl-tech-software%2Fqt-traffic-light","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhcl-tech-software%2Fqt-traffic-light","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhcl-tech-software%2Fqt-traffic-light/lists"}