Skip to content

02-signal-member/main.cpp

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

The output of this example is:

1
Hello World!
 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
34
35
36
37
38
39
40
41
42
43
/*
  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 <kdbindings/signal.h>

#include <iostream>
#include <string>

using namespace KDBindings;

class Button
{
public:
    Signal<> clicked;
};

class Message
{
public:
    void display() const
    {
        std::cout << "Hello World!" << std::endl;
    }
};

int main()
{
    Button button;
    Message message;

    button.clicked.connect(&Message::display, &message);
    button.clicked.emit();

    return 0;
}

Filename: 02-signal-member/main.cpp


Updated on 2024-03-19 at 00:03:31 +0000