Skip animation if its target is null
-
Qt 6.2.0, I have this animation:
SequentialAnimation { id: selectedContent running: false ParallelAnimation { PropertyAnimation { target: view; properties: "opacity"; duration: 500; to: 0.0} PropertyAnimation { target: view.currentItem; properties: "y"; duration: 500; to: view.height * 2} } ScriptAction { script: flow.selectedContent(view.currentIndex) } ParallelAnimation { PropertyAnimation { target: view; properties: "opacity"; duration: 500; to: 1.0} PropertyAnimation { target: view.currentItem; properties: "y"; duration: 500; to: view.height / 2} } }It may happen that
view.currentItemis null. When it happens the application crashes.
How can I skip aParallelAnimationanimation itstargetisnull?
I tried to put anifclause inside but it's not a valid syntax.I cannot just skip the whole
SequentialAnimationbecause the execution of the script can change theview.currentItem. That means it should, say, skip the firstParallelAnimation(due toview.currentItem === null) but not the second one (as the script has changed it and now it's notnullanymore). -
Could you share a bit more about what you want to do to give more context? We might find another solution to your problem.
Also what isview? aStackView, aListView, aContainer? -
viewis aPathView:PathView { id: view property int item_gap: 60 property bool isSEM anchors.fill: parent pathItemCount: 3 preferredHighlightBegin: 0.5 preferredHighlightEnd: 0.5 highlightRangeMode: PathView.StrictlyEnforceRange highlightMoveDuration: 1000 snapMode: PathView.SnapToItem rotation: -90 model: modelContent delegate: DelegateContent { } path: Path { startX: view.width + item_gap; startY: view.height / 2 PathAttribute { name: "iconScale"; value: 0.7 } PathAttribute { name: "iconOpacity"; value: 0.1 } PathAttribute { name: "iconOrder"; value: 0 } PathLine {x: view.width / 2; y: view.height / 2; } PathAttribute { name: "iconScale"; value: 1 } PathAttribute { name: "iconOpacity"; value: 1 } PathAttribute { name: "iconOrder"; value: 9 } PathLine {x: -item_gap; y: view.height / 2; } } ...It may happen that the model has zero elements, so there is no
currentItem(null). The script will populate the model so the second part of the animation should run anyway. For this reason I asked how to skip (or just avoid a crash!) if the target of an animation isnull. -
Does 'crash' in your case refer to a segfault? A total abrupt abnormal termination, such as the kind resulting in a dump?
If so, can you capture and post the backtrace/callstack of the crash?
Can you share a minimum reproducible sample project? (Maybe even a pure QML mini-app that could be launched with qmlscene and bypass the need to compile anything?)
-
Does 'crash' in your case refer to a segfault? A total abrupt abnormal termination, such as the kind resulting in a dump?
If so, can you capture and post the backtrace/callstack of the crash?
Can you share a minimum reproducible sample project? (Maybe even a pure QML mini-app that could be launched with qmlscene and bypass the need to compile anything?)
@KH-219Design yes, it's a segmentation fault.
Would you please tell me how to capture the backtrace/callstack? When debugging I can see only a lot of disassembled code, but no one function (in any thread) is my code.I can prepare a sample project for you. In the meanwhile, can we generalize a bit the question?
How to skip a step in a
SequentialAnimationif some conditions are met?