aboutsummaryrefslogtreecommitdiffstats
path: root/qt-qml/tests/manual/qml-syntax/method.qml
blob: aef912a63430020a946a026e462950d9ea08d512 (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
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only

import QtQuick

Item {
    function myfunc() { return 3; } // comment
    function myfunc() { // comment
        // comment
        return 3;
    }

    function myfunc(): int {
        return 3;
    }

    function myfunc(): int {
        return 3;
    }

    function myfunc(a: int, b: date, c: Item): int {
        return a + b + c.prop;
    }

    // arrow function
    Component.onCompleted: () => {
        console.log("aaa");
    }

    Keys.onPressed: (event)=> {
        if (event.key == Qt.Key_Left) {
            console.log("move left");
            event.accepted = true;
        }
    }

    // inside child item
    MouseArea {
        function insideItem(a: int, b: date): int {
            return a + b;
        }

        // arrow function
        onClicked: (e) => {
            console.log("clicked", e);
            insideItem(a, b)
        }

        // without (), {}
        onPressed: mouse => root.activated(mouse.x, mouse.y)
    }
}