summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2018-07-06 15:19:11 +0200
committerMitch Curtis <mitch.curtis@qt.io>2018-07-10 07:39:48 +0000
commit77fa37ff3db59eef589fc2f89a26c1af568b3d76 (patch)
treeab374cd9bc4cb7b878a14984e7dc007388c28e3a /src
parent085d13f6ae3009bd157bfce6a062453d95298cbc (diff)
Doc: add section about type safety
Change-Id: I6ae5be8480ff817651c66a1617dceeefb96e5712 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/quick/doc/src/guidelines/qtquick-bestpractices.qdoc30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/quick/doc/src/guidelines/qtquick-bestpractices.qdoc b/src/quick/doc/src/guidelines/qtquick-bestpractices.qdoc
index a097ec32d3..5f7b153a7b 100644
--- a/src/quick/doc/src/guidelines/qtquick-bestpractices.qdoc
+++ b/src/quick/doc/src/guidelines/qtquick-bestpractices.qdoc
@@ -367,6 +367,36 @@ properties are enough.
\li \l{Qt Quick Layouts Overview}
\endlist
+\section1 Type Safety
+
+When declaring properties in QML, it's easy and convenient to use the "var" type:
+
+\code
+property var name
+property var size
+property var optionsMenu
+\endcode
+
+However, this approach has several disadvantages:
+\list
+ \li If a value with the wrong type is assigned, the error reported will point
+ to the location of the property declaration, as opposed to the location
+ where the property was assigned to. This slows down the development
+ process by making it more difficult to track down errors.
+ \li Static anaylsis to catch errors like the ones mentioned above is not
+ possible.
+ \li The actual underlying type of the property is not always immediately clear
+ to the reader.
+\endlist
+
+Instead, always use the actual type where possible:
+
+\code
+property string name
+property int size
+property MyMenu optionsMenu
+\endcode
+
\section1 Performance
For information on performance in QML and Qt Quick,