KDBindings API Documentation  1.0.95
05-property-bindings/main.cpp

An example of how to use makeBoundProperty() to create a KDBindings::Property that is automatically updated once any of its inputs change.

The output of this example is:

The initial size of the image = 1920000 bytes
The new size of the image = 4608000 bytes
The new size of the image = 8294400 bytes
/*
This file is part of KDBindings.
SPDX-FileCopyrightText: 2021 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
Author: Sean Harmer <sean.harmer@kdab.com>
SPDX-License-Identifier: MIT
Contact KDAB at <info@kdab.com> for commercial licensing options.
*/
#include <iostream>
using namespace KDBindings;
class Image
{
public:
const int bytesPerPixel = 4;
Property<int> width{ 800 };
Property<int> height{ 600 };
const Property<int> byteSize = makeBoundProperty(bytesPerPixel * width * height);
};
int main()
{
Image img;
std::cout << "The initial size of the image = " << img.byteSize.get() << " bytes" << std::endl;
(void)img.byteSize.valueChanged().connect([](const int &newValue) {
std::cout << "The new size of the image = " << newValue << " bytes" << std::endl;
});
img.width = 1920;
img.height = 1080;
return 0;
}
The main namespace of the KDBindings library.
Definition: binding.h:21
auto makeBoundProperty(T &&...args)
Helper function to create a Property with a Binding.
Definition: binding.h:328

© Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
KDBindings
Reactive programming & data binding in C++
https://github.com/KDAB/KDBindings/
Generated by doxygen 1.9.1