summaryrefslogtreecommitdiff
path: root/doc/qtcreator/src/qtquick/qtquick-connection-editor-signals.qdoc
blob: f1d39786b7ec92e2506d7780207ce4a3c5ab5532 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/****************************************************************************
**
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Creator documentation.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
**
****************************************************************************/

/*!
    \previouspage qmldesigner-connections.html
    \page quick-signals.html
    \nextpage quick-property-bindings.html

    \title Connecting Components to Signals

    A signal and handler mechanism enables components to respond to application
    events, which are represented by \e signals. When a signal is emitted, the
    corresponding \e {signal handler} is invoked to respond to the event by
    using scripts or other operations placed in the handler.

    To receive a notification when a particular signal is emitted for a
    particular component, the component definition should declare a signal handler
    named \e {on<Signal>} where \e {<Signal>} is the name of the signal, with
    the first letter capitalized. The signal handler should contain the
    JavaScript code to be executed when the signal handler is invoked.

    Components have predefined signals that are emitted when users interact with
    the application. For example, the \l {Mouse Area} component has a \c clicked
    signal that is emitted whenever the mouse is clicked within the area. Since
    the signal name is \c clicked, the signal handler for receiving this signal
    is named \c onClicked.

    A signal is automatically emitted when the value of a property changes.
    This type of signal is a \e{property change signal} and signal handlers
    for these signals are written in the form \c on<Property>Changed, where
    \e <Property> is the name of the property, with the first letter
    capitalized.

    For example, the Mouse Area component has a \c pressed property. To receive
    a notification whenever this property changes, you would use a signal handler
    called \c onPressedChanged.

    For more information about signals and signal handlers, see
    \l{Signal and Handler Event System}.

    You can connect components to signals that are available to them in
    \uicontrol Connections.

    \image qmldesigner-connections.png

    To connect components to signals:

    \list 1
        \li Select \uicontrol View > \uicontrol Views >
            \l {Connection View} > \uicontrol {Connections}.
        \li Select the \inlineimage plus.png
            (\uicontrol Add) button to add a connection.
        \li Double-click the value in the \uicontrol Target column to add the
            component to connect to a signal.
        \li Double-click the value in the \uicontrol {Signal Handler} column to
            select the signal that the connection will listen to from a list of
            all signals available for the component.
        \li Double-click the value in the \uicontrol Actions column to specify
            the action to perform when the signal is emitted. You use JavaScript
            to specify the actions.
    \endlist

    Right-click a connection and select \uicontrol {Open Connection Editor}
    in the context menu to specify the connection in
    \uicontrol {Connection Editor}.

    \if defined(qtcreator)
    For an example of using the \uicontrol {Connections} view, see
    \l{Connecting Mouse Clicks to State Changes}.
    \else
    For examples of using the \uicontrol {Connections} view, see:

    \list
        \li \l{Connecting Buttons to States} in \l{Log In UI - Part 3}
        \li \l{Connecting Buttons to State Changes} in \l{Washing Machine UI}
    \endlist
    \endif

    \section1 Adding Signal Handlers

    If a signal handler that you need is not listed in the
    \uicontrol {Signal Handler} column, you can add it:

    \list 1
        \li Right-click a component in the \l Navigator or \l {Form Editor} view
            and select \uicontrol {Add New Signal Handler} in the context menu.
        \li In the \uicontrol Signal field, select the signal to handle.
            \image qmldesigner-implement-signal-handler.png "Implement Signal Handler dialog"
        \li Select the radio buttons to filter the list to only display
            frequently used signals or property changes.
        \li Select \uicontrol OK.
    \endlist

    The added signal handler is automatically \l{Adding Property Aliases}
    {exported as a property}.

    \section1 Adding Actions and Assignments

    You use the \uicontrol {Connection Editor} to create the JavaScript
    expressions for \e actions and \e assignments. An \e action connects
    an component to a signal, whereas an \e assignment fetches property values
    from another component.

    For more information about the logical operators that you can use to
    construct conditional expressions, see \l {Summary of Logical Operators}.

    To create JavaScript expressions for actions:

    \list 1
        \li Select \uicontrol {Open Connection Editor} in the context menu
            in \uicontrol {Connections}.
            \image qtquick-connection-editor-action.png
        \li Select \uicontrol Action as the type of the connections component.
        \li Select the component to connect to a signal.
        \li Select the action to perform when the signal is emitted.
    \endlist

    To create JavaScript expressions for assignments:

    \list 1
        \li Select \uicontrol {Open Connection Editor} in the context menu
            in \uicontrol {Connections}.
            \image qtquick-connection-editor-assignment.png
        \li Select \uicontrol Assignment as the type of the connections
            component.
        \li Select the target component for the property assignment.
        \li Select the property of the target component to assign a value to.
        \li Select the source component for the property assignment.
        \li Select the property of the source component to fetch the value from.
    \endlist
*/