How to create a property binding in Qt/C++?

In Qt, some QObjects have certain properties that can be "bound" using signals and slots:

auto *someWidget = QPushButton(/* ... */);
auto *otherRelatedWidget = QLabel( /* ... */ );
// windowTitle is a property for both QWidgets
QObject::connect(someWidget, &QWidget::windowTitleChanged,
                 otherRelatedWidget, &QWidget::setWindowTitle);

Apart from this, you can still connect other signals and slots, even if they're not associated to properties.

I've got to point out that there is no syntax sugar for doing this. See the properties documentation for more info.

Tags:

C++

Qt

Qml