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 add element to Composition

To add an element to the Composition, we:

  • Increase the elements.counter to be able to generate a unique object name for the new element
  • Instantiate the Element QML component as a child of the elements entity, by  passing a few creation parameters to the createObject call; the shape we get from the GUI option selected by the user, and the initial translation by a vector of random numbers:
// cccomposer/main.qml...function addElementToComposition(shape) {    elements.counter += 1;    var element = elements.factory.createObject(                composition.elements,                {                    shape: shape,                    objectName: "element"+elements.counter,                    translation: Qt.vector3d(                                Math.random()*3, 0.0, Math.random()*3)                 });    elements.list.push(element);}... ...

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