Properties

In Chapter 3, Qt GUI Programming, we edited predefined properties of widgets in the form editor and used their getter and setter methods in the code. However, until now, there wasn't a real reason for us to declare a new property. It'll be useful with the Animation framework, so let's pay more attention to properties.

Only classes that inherit QObject can declare properties. To create a property, we first need to declare it in a private section of the class (usually right after the Q_OBJECT mandatory macro) using a special Q_PROPERTY macro. That macro allows you to specify the following information about the new property:

  • The property name—a string that identifies the property in the Qt meta system.
  • The property type—any valid ...

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.