summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2021-07-28 15:01:31 +0200
committerMaximilian Goldstein <max.goldstein@qt.io>2021-07-29 09:20:36 +0200
commit0c6f907b27d3fa31ce695286d0de101a8a2657b3 (patch)
tree0445ea1911d6a24609fc0ba1483dddc69ef44e15
parent33da36326d60346103f3c8738c726da818f127a9 (diff)
downloadqtdoc-0c6f907b27d3fa31ce695286d0de101a8a2657b3.tar.gz
qmlapp/codingconventions: Encourage using named signal parameters
Pick-to: 6.2 Task-number: QTBUG-92970 Change-Id: I11bf37cae634434a8ad950a902518a9001bf02bb Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--doc/snippets/qmlapp/codingconventions/signalhandler.qml57
-rw-r--r--doc/src/qmlapp/codingconventions.qdoc6
2 files changed, 63 insertions, 0 deletions
diff --git a/doc/snippets/qmlapp/codingconventions/signalhandler.qml b/doc/snippets/qmlapp/codingconventions/signalhandler.qml
new file mode 100644
index 00000000..3a5ac9af
--- /dev/null
+++ b/doc/snippets/qmlapp/codingconventions/signalhandler.qml
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick
+
+//![0]
+MouseArea {
+ onClicked: (event) => { console.log(`${event.x},${event.y}`); }
+}
+//![0]
diff --git a/doc/src/qmlapp/codingconventions.qdoc b/doc/src/qmlapp/codingconventions.qdoc
index a2969686..e17c4828 100644
--- a/doc/src/qmlapp/codingconventions.qdoc
+++ b/doc/src/qmlapp/codingconventions.qdoc
@@ -82,6 +82,12 @@ users and tooling to reason about an external property's type.
Additionally they remove assumptions that a component otherwise has to make about the environment
in which it is created.
+\section1 Signal handlers
+
+When handling parameters in signal handlers use functions which name them explicitly:
+
+\snippet qmlapp/codingconventions/signalhandler.qml 0
+
\section1 JavaScript Code
If the script is a single expression, we recommend writing it inline: