diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-12-18 15:51:38 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-01-27 15:01:54 +0100 |
commit | f07c6f52ac4e336bd49c5d3cdaf89803460ba3bf (patch) | |
tree | ce26194e0efb4fb6b2babb4b992724362a3bbb25 /src/corelib/doc/snippets | |
parent | 16b8d766abe86868597b30cec03152355ee1a91b (diff) |
QBindable: add initial documentation
Change-Id: I43681093c8819289037c76bd9c05b88a6da8311b
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/doc/snippets')
-rw-r--r-- | src/corelib/doc/snippets/code/src_corelib_kernel_qproperty.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qproperty.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qproperty.cpp index 4cb7c1c0ce..a402a70599 100644 --- a/src/corelib/doc/snippets/code/src_corelib_kernel_qproperty.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qproperty.cpp @@ -49,6 +49,7 @@ ****************************************************************************/ #include <QObject> +#include <QDebug> //! [0] class MyClass : public QObject @@ -107,3 +108,14 @@ private: Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(MyClass, CustomType xProp, CustomType(5, 10), &MyClass::xChanged) //! [2] + +void usage_QBindable() { + //! [3] + MyClass *myObject; + QBindable<int> bindableX = myObject->bindableX(); + qDebug() << bindableX.hasBinding(); // prints false + QProperty<int> y {42}; + bindableX.setBinding([&](){ return 2*y.value(); }); + qDebug() << bindableX.hasBinding() << myObject->x(); // prints true 84 + //! [3] +} |