KDBindings API Documentation  1.0.95
03-member-arguments/main.cpp

An example of how to connect a member function with arguments to a KDBindings::Signal.

The output of this example is:

Bob received: Have a nice day!
Alice received: Thank you!
/*
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 Person
{
public:
Person(std::string const &name)
: m_name(name)
{
}
Signal<std::string const &> speak;
void listen(std::string const &message)
{
std::cout << m_name << " received: " << message << std::endl;
}
private:
std::string m_name;
};
int main()
{
Person alice("Alice");
Person bob("Bob");
auto connection1 = alice.speak.connect(&Person::listen, &bob);
auto connection2 = bob.speak.connect(&Person::listen, &alice);
alice.speak.emit("Have a nice day!");
bob.speak.emit("Thank you!");
connection1.disconnect();
connection2.disconnect();
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