Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QPropertyAlias Class Reference

\inmodule QtCore More...

+ Collaboration diagram for QPropertyAlias:

Detailed Description

\inmodule QtCore

The QPropertyAlias class is a safe alias for a QProperty with same template parameter.

QPropertyAlias<T> wraps a pointer to a QProperty<T> and automatically invalidates itself when the QProperty<T> is destroyed. It forwards all method invocations to the wrapped property. For example:

QProperty<QString> *name = new QProperty<QString>("John");
QProperty<int> age(41);
QPropertyAlias<QString> nameAlias(name);
QPropertyAlias<int> ageAlias(&age);
QProperty<QString> fullname;
fullname.setBinding([&]() { return nameAlias.value() + " age: " + QString::number(ageAlias.value()); });
qDebug() << fullname.value(); // Prints "John age: 41"
*name = "Emma"; // Marks binding expression as dirty
qDebug() << fullname.value(); // Re-evaluates the binding expression and prints "Emma age: 41"
// Birthday is coming up
ageAlias.setValue(age.value() + 1); // Writes the age property through the alias
qDebug() << fullname.value(); // Re-evaluates the binding expression and prints "Emma age: 42"
delete name; // Leaves the alias in an invalid, but accessible state
nameAlias.setValue("Eve"); // Ignored: nameAlias carries a default-constructed QString now
ageAlias.setValue(92);
qDebug() << fullname.value(); // Re-evaluates the binding expression and prints " age: 92"
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:8084
#define qDebug
[1]
Definition qlogging.h:164
GLuint name

The documentation for this class was generated from the following file: