Sunday, 11 June 2017

TrafficControl: Modifying Existing Station QML Items from C++

The blog posts has been scarse, due to positive news in my closest family. I'll be a busy family man for the coming decades but I'll keep writing on this blog.

When something happens to a station in the C++ part of the program, the corresponding QML item shall be modified. I got inspiration from a post on Andrew Jones' blog, regarding QML/C++ interactions using signals/slots.

Train::move() will trigger signal that will be caught by the QML part and update the map.
  • A train enters a station
  • A signal is trigged by train::move(), containing the station name, the train name and a description of the event
  • A slot in the QML part recieves the signal and extracts the information.
  • The corresponding QML item is updated
The new signal is called stationChangedSignal, and will contain three qVariants:
  1. The first will always contain the name of the station that is changing
  2. The second parameter will define what has happened (in this case: "train arrival")
  3. The third parameter will define any other items/objects (in this case, the train name)
In this case, I'll let the train::runningToOpeningState() emit a signal:
stationChangedSignal("LundC", "train arrival",  "Hedy_Lamarr")

This signal will tell the QML part that a train named "Hedy_Lamarr" has arrived to the station LundC".

The current commit, 1c198ff, has introduced a signal without any parameters. I still have some problems parsing a signal containing qVariant data to the QML javascript. More about that in the next blog post.

No comments:

Post a Comment