summaryrefslogtreecommitdiffstats
path: root/howtos/handle_cpp_signals/index.rst
blob: d7c62bc4f19e07e6cf17707b5aeb7d4ad0ab3c63 (plain)
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
..
    ---------------------------------------------------------------------------
    Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
    All rights reserved.
    This work, unless otherwise expressly stated, is licensed under a
    Creative Commons Attribution-ShareAlike 2.5.
    The full license document is available from
    http://creativecommons.org/licenses/by-sa/2.5/legalcode .
    ---------------------------------------------------------------------------

How to hadle signals from a C++ Object
======================================

To Handle signals from a C++ objects in your QML code, you need to add a signal handler within the object in the QML side that refers to the signal defined in the C++ code as follows:

.. code-block:: cpp

    // file.cpp

    class MyCppObject: public QObject
    {
        ...
        signals:
        void objectSelected(const QString& message);

    }

And here how to handle the signal above in QML:

.. code-block:: js

    // file.qml

    MyObject {
        ...
        onObjectSelected :
        console.log(message)
    }