diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-11-23 14:08:37 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-12-03 21:12:42 +0100 |
commit | 6eb35df60e061b9ce4e88f97a174216e2b1c617f (patch) | |
tree | 9619b6de7eca4b6e727fdd04de87e9dee1fe1e0b /examples | |
parent | 77579924957af07dc9bfb2a7309caf606bcffab0 (diff) |
QML engine: Deprecate DefaultMethod
Assigning objects to signal handlers can be convenient, as seen in the
examples which use it together with ListView.onRemove.
However, that convenience makes it hard to reason about what actually
happens. Moreover, the only user of that functionality are the Animation
classes, and the usage of DefaultMethod is not documented anywhere.
[ChangeLog][QtQml] Assigning an object to a signal handler is deprecated.
Instead, create the object, give it an id, and call the desired slot
from the signal handler. For instance, instead of of
ListView.onRemove: SequentialAnimation {...}
use
SequentialAnimation {id: removeAnimation; ...}
ListView.onRemove: removeAnimation.start()
A warning will be printed whenever an assignment of an object to a
signal handler occurs. The warning can be controlled via the
qt.qml.defaultmethod logging category.
Change-Id: I001ddf4d7933871977f84a5e012d020fb043cc64
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/quick/views/listview/dynamiclist.qml | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/examples/quick/views/listview/dynamiclist.qml b/examples/quick/views/listview/dynamiclist.qml index f37aab98e2..973d3ce389 100644 --- a/examples/quick/views/listview/dynamiclist.qml +++ b/examples/quick/views/listview/dynamiclist.qml @@ -200,18 +200,22 @@ Rectangle { // Animate adding and removing of items: //! [1] - ListView.onAdd: SequentialAnimation { + SequentialAnimation { + id: addAnimation PropertyAction { target: delegateItem; property: "height"; value: 0 } NumberAnimation { target: delegateItem; property: "height"; to: 80; duration: 250; easing.type: Easing.InOutQuad } } + ListView.onAdd: addAnimation.start() - ListView.onRemove: SequentialAnimation { + SequentialAnimation { + id: removeAnimation PropertyAction { target: delegateItem; property: "ListView.delayRemove"; value: true } NumberAnimation { target: delegateItem; property: "height"; to: 0; duration: 250; easing.type: Easing.InOutQuad } // Make sure delayRemove is set back to false so that the item can be destroyed PropertyAction { target: delegateItem; property: "ListView.delayRemove"; value: false } } + ListView.onRemove: removeAnimation.start() } //! [1] } |