KDBindings API Documentation  1.0.95
04-simple-property/main.cpp

An example of how to create a KDBindings::Property and use its valueChanged() KDBindings::Signal to receive notifications whenever the value of the KDBindigns::Property changes.

The output of this example is:

The new value is 42
The new value is 69
Property value is 69
/*
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>
#include <string>
using namespace KDBindings;
class Widget
{
public:
Widget(std::string const &name)
: value(0)
, m_name(name)
{
}
Property<int> value;
private:
std::string m_name;
};
int main()
{
Widget w("A cool widget");
(void)w.value.valueChanged().connect([](int newValue) {
std::cout << "The new value is " << newValue << std::endl;
});
w.value = 42;
w.value = 69;
std::cout << "Property value is " << w.value << std::endl;
return 0;
}
The main namespace of the KDBindings library.
Definition: binding.h:21

© 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