Time for action – Public interface of the dialog

The next thing to do is to allow to store and read player names from outside the dialog—since the ui component is private, there is no access to it from outside the class code. This is a common situation and one that Qt is also compliant with. Each data field in almost every Qt class is private and may contain accessors (a getter and optionally a setter), which are public methods that allow us to read and store values for data fields. Our dialog has two such fields—the names for the two players.

Names of setter methods in Qt are usually started with set, followed by the name of the property with the first letter converted to uppercase. In our situation, the two setters will be called setPlayer1Name ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.