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

In QML, it is easy to write the creation of property bindings, for example:

Rectangle { width: parent.width } 

Is it possible to do this in C ++?

+6
source share
1 answer

In Qt, some QObject have certain properties that can be โ€œconnectedโ€ 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); 

In addition, you can connect other signals and slots, even if they are not related to properties.

I must point out that there is no syntactic sugar for this. See the documentation for more information.

+5
source

All Articles