O'Reilly logo

Qt 5 Projects by Marco Piccolino

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing remove element from composition

To remove an element from a Composition, we can loop over the list of existing elements, and destroy it if its objectName corresponds to the value of elements.selectedElement:

// cccomposer/main.qml...function removeElementFromComposition() {    for (var i=0; i < elements.list.length; ++i) {        if (elements.list[i].objectName === elements.selectedElement) {            elements.list[i].destroy();            elements.selectedElement = "";            break;        }    }}...

For this to work, however, we must ensure that elements.selectedElement is filled with the objectName of the last Element that was selected by the user. This can be achieved by notifying the elements business object whenever an element instance was selected, via a signal-slot ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required