Exercise (COMPULSORY): Inheritance and Qt

This week we will revise using Qt. In addition we'll get to know inheritance as a part of programming both from the point of view of Qt and polymorphism.

As the compulsory part of the exercise you must complete: Adding a start dialog. The submission is done with the help of version control. Remember to commit your work frequently.

The files needed in this task can be pulled from version control. They are in repository ``student_template_project` https://course-gitlab.tuni.fi/tie-0240x-ohjelmointi-3-programming-3-2020-2021/student_template_project. You must set it as a remote to your local repository. The codes needed in this exercise are in the directory EX4. Note that you do not have rights to update the repository. Note! You need to do this only once!

  • .gitlab-ci.yml: CI/CD configuration at the root of the repository
  • EX4:
    • Inheritance:
      • Inheritance.pro
      • constants.hh, fastball.hh, fastball.cc, main.cc, mainwindow.cc, movingobject.cc, movingobject.hh, movingobjectgraphics.cc, movingobjectgraphics.hh, objectcontroller.cc, objectcontroller.hh

Adding a Start Dialog

Add a starting window to the program to ask the user some useful information regarding the program. It can be for example the amounts of objects you want ot see on the screen. You can get a new window by clicking project with the right mouse button Add new->Qt->Qt Designer Form Class.

Note that Qt created new .h, .cpp, and .ui files. Complete the dialog. Add buttons for starting and closing the program and the needed fields for collecting the information needed. Connect the click signals of the buttons to the slots reject() and accept(). Documentation on dialogs and signals can be found here .

Write code to show the dialog in the main program. To be able to do so, see exec() in Qt documentation.

Next step is to pass the user-given information to the main program. This can be done with signals and slots, i.e. the dialog signals the user-given values to the main program i.e. at least the amount of objects to be drawn on the screen. For this purpose, you should create a new signal for the dialog, with the user-given value as its parameter.

To enable your dialog window to send signals, you should add necessary signals to the signals interface and emit them in the code in order to get the required functionality.

Into the MainWindow you need to add the code for creating your dialog and connection of the signal to the spawnObjects() slot.

Polymorphism in use

There is an abstract base class MovingObject in the program. It has one derived class FastBall that overrides the function virtual void move() = 0. Implement a class OddBall where the way to move is chosen by you. This is easiest by creating a derived class from MovingObject. You get the objects included into the program by adding the handling of the type ObjectType::ODDBALL into the spawnObjects( ); signal in the main window.

Submission

Submit your work with a tag starting with EX4_submission.

A+ presents the exercise submission form here.

Posting submission...