Skip to content

01-simple-connection/main.cpp

A simple example of how to create a KDBindings::Signal and connect a lambda to it.

The output of this example is:

1
The answer: 42
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
  This file is part of KDBindings.

  SPDX-FileCopyrightText: 2021-2022 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 <kdbindings/signal.h>

#include <iostream>
#include <string>

using namespace KDBindings;

int main()
{
    // Create new signal
    Signal<std::string, int> signal;

    // Connect a lambda
    signal.connect([](std::string arg1, int arg2) {
        std::cout << arg1 << " " << arg2 << std::endl;
    });

    // Emit the signal and the lambda is called
    signal.emit("The answer:", 42);

    return 0;
}

Filename: 01-simple-connection/main.cpp


Updated on 2022-04-12 at 00:03:57 +0000

Back to top