A road traffic simulator with three different Qt-based visualization approaches. Cars and roads based on python solution from BilHim/trafficSimulator and yossidoctor/AI-Traffic-Lights-Controller
- Flexible rendering system with three independent implementations
- Separation of logic and presentation through Common, Simulation and Via components
- Simulation state managed via State pattern
- Road network with straight sections and turns - AllRoads
- Traffic light control with fixed cycles - TrafficSignal
- Vehicle generation with different routes - VehicleGenerator
- Realistic movement physics Vehicle including:
- Acceleration/braking
- Distance keeping
- Traffic light response
Three implementation approaches with common functionality:
-
QGraphicsView:
- Classic approach with main-thread rendering
- Uses QGraphicsPolygonItem for drawing
- Simpler implementation but less performant
-
QQuickItem:
- Modern Scene Graph rendering
- Separate render thread (high performance)
- Uses QSGGeometryNode for efficient drawing
-
QQuickPaintedItem:
- QPainter-based rendering in separate thread
- More flexible but less performant than QQuickItem
- Uses standard Qt painting methods
Three implementations following a hierarchical class structure:
- Base → Zoomable → Draggable → LoopLauncher/Main
Each layer adds specific functionality:
- Zoomable: Mouse wheel zoom implementation
- Draggable: Scene dragging/panning support
- LoopLauncher: Main simulation loop handling
-
Alternative QML resource locator - QrcLocatorReplacement:
- Enables QML usage without Qt plugins in MSVC
- Searches for QML files in multiple paths
- Uses QQmlAbstractUrlInterceptor for qrc path redirection
-
MOC-free operation support:
- Conditional compilation with A0S_QT_PRO
- Alternative Q_OBJECT implementation via W_OBJECT/W_OBJECT_IMPL
- Compilation without Qt's meta-object system
-
Unified polygon handling:
- Consistent QPolygonF usage across all implementations
- Qt6 compatibility adaptations:
- Replaced deprecated DrawTriangleFan with DrawTriangleStrip
- Replaced DrawLineLoop with DrawLineStrip
- Benefits:
- Compatibility with both Qt5 and Qt6
- More modern and efficient rendering methods
- Improved graphics performance
The project supports two build methods:
-
Standard build -
HelloQt.pro:- For Qt Creator and other IDEs
- Uses standard Qt build system
-
MOC-free build -
HelloQt(Non_MocUic).sln:- For Visual Studio 2019
- Specifically configured for Qt 5.15
- Without Qt 5.15 you may encounter errors like:
The code execution cannot proceed because Qt5Cored.dll was not found The code execution cannot proceed because Qt5Guid.dll was not found The code execution cannot proceed because Qt5Quickd.dll was not found The code execution cannot proceed because Qt5Widgetsd.dll was not found
- Qt 5.15 (exact version required)
- Microsoft Visual Studio 2019 Community
- Qt 5.15 or later
- Standard Qt build system
- Any IDE supporting .pro files (Qt Creator, CLion, etc.)
- Launch the application
- Use mouse wheel to zoom
- Drag the scene with left mouse button
- Observe vehicle movement and traffic light operation
PRs and questions are welcome! No strict requirements for contributors.
- Qt - for the framework
- BilHim/trafficSimulator - for the model basis
- yossidoctor/AI-Traffic-Lights-Controller - for traffic light ideas
- woboq/verdigris - for MOC-free operation
Project is MIT licensed. See LICENSE for details.
