Meeting 13: Qt Signals and Slots

Today we will learn about a variation of the Observer design pattern that is used prominently within Qt, called signals and slots.

Links:

Exercise 13: Qt Signals and Slots

GitHub Invitation URL: exercise13

Steps:

  1. Clone the assignment for today after accepting the GitHub invitation at the link above. The repository contains four files:
  1. Add code to the TrafficLight class to add a slot called toggle to change the light currently lit. The sequence should go red->green->yellow->red repeating after that. You will need to add some internal members to the TrafficLight class to accomplish this.

  2. Read the documentation for QTimer and, in the main function of main.cpp, add code to setup and start a timer that goes off every one second, resulting in the traffic light being toggled. This will require connecting a signal from the timer to the slot implemented in step 2.

  3. Build and run your application. Does the light change in the correct sequence?

  4. Now, use git to commit the source files changed to the local repository.

  5. Finally, use git push to synchronize the repository with that on GitHub.

You have completed the Exercise.