Qt World Summit: Submit your Presentation

When to use Q_PROPERTY

  • When does one need to declare and define Q_PROPERTY in a class. Or putting the question another way around, when does a class require Q_PROPERTY?

  • Well one case where you would "need" to use it is if you wanted to access a property indirectly through it's name, or wanted to have a class that could be "discovered" through its meta properties. The "help topic":http://qt-project.org/doc/qt-5/properties.html has a pretty good description.

    I know when I'm using Qt Quick for my front end and I want the QML to have access to my C++ getters and setters Q_PROPERTY is the tool I reach for.

Log in to reply