Saturday 22 July 2017

TrafficControl: Adding Trains to the QML Map - Coding

The trains are added in the C++ and QML part when the "ADD TRAIN" command is used. Initially, the trains are placed on a default location on the map,


When the station is specified (TRAIN SET CURRENT STATION), the train will be visible and get proper coordinates, according to the station name. In order to do this, the tcStation and tcTrack need to have their own coordinates in the C++ part. Until now, C++ has only passed the parameters to QML.
The train positions will be updated using qmlTrainPositionSlot.

From now on, the C++ station object will be aware of its own coordinates.

The train will be relocated using signal/slot mechanism, with position, delay status and number of passengers. For the current commit, the signal qmlTrainPositionSignal is only emitted when the train arrives to a station.
The red dots are the trains (currently only updated when arriving to stations)


The train from Ada_Lovelace from Gunnesbo has arrived to Lund
In the next blog post, I'll implement a function that will help the trains to calculate their coordinates based on the position of the tracks.

A side note: When compiling, the error message "Cannot convert QVariant to QVariant" might pop up. Include QVariant to the header file to resolve that issue.

No comments:

Post a Comment