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

Adding the usecases

Along the same lines, we can add another QtObject to encapsulate the usecases, which will be implemented as JavaScript methods of this object:

// cccomposer/main.qml...Window {    ...    QtObject {        id: elements        ...    }    QtObject {        id: usecases        function addElementToComposition(shape) {}        function removeElementFromComposition() {}        function saveCompositionToImage() {}    }    ...}

Now that we have methods for the usecases, we can wire these to the previously created buttons:

// cccomposer/main.qml...            Button {                text: "add element"                anchors.horizontalCenter: parent.horizontalCenter                onClicked: {                    usecases.addElementToComposition(shapeSelector.shape);                }            }            Button {                text: "remove element"                anchors.horizontalCenter: parent.horizontalCenter                onClicked: ...

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