Adding Connections

You can use the Connections view to:

  • Connect objects to signals.
  • Specify dynamic properties for objects.
  • Create bindings between the properties of two objects.
  • Manage backend QObjects.

For examples of adding connections, see Creating Scalable Buttons and Borders.

Connecting Objects to Signals

To connect objects to signals in QML, create Connections objects.

To create the connections:

  1. Select the Connections tab.
  2. Select the (Add) button to add a connection.
  3. Select Target to add the object to connect to a signal.
  4. Select Signal Handler to select the signal that the connection will listen to from a list of all signals available for the object.
  5. Select Actions to specify the action to perform when the signal is emitted. You use JavaScript to specify the actions.

Specifying Dynamic Properties

You can bind Properties to dynamic expressions to define global properties for an object that can be read by other objects. For example, you can specify global properties for the root object that you can use in the child objects.

To specify dynamic properties for an object:

  1. Select the Properties tab.
  2. Select Item to select the object to specify the property for.
  3. Select Property to give a name to the property.
  4. Select Property Type to specify the type of the property.
  5. Select Property Value to specify the value of the property.

Adding Bindings Between Properties

To dynamically change the behavior of an object, you can create a Property Binding between the properties of two objects.

To bind a property of an object to the property of another object:

  1. Select the Bindings tab.
  2. Select the (Add) button to add a binding.
  3. Select Item to select the target object whose property you want to change dynamically.
  4. Select Property to select the property to bind to a source property.
  5. Select Source Item to select the object whose property you want to use to determine the behavior of the target object.
  6. Select Source Property to select the property to bind the target property to.

Managing C++ Backend Objects

Many applications provide QObject objects implemented in C++ that work as a bridge between QML and C++. Such objects are typically registered with qmlRegisterType or qmlRegisterSingletonType and then used by QML to communicate with the C++ backend. Another example of such objects are the state machines created by the Qt SCXML Compiler.

Backend objects in a QML file are accessible if the QML file contains the required imports. In addition, for a non-singleton QObject, a dynamic property that contains the QObject must be specified.

A local QObject is instantiated in the current .qml file, as follows:

property MyType myType: MyType {}.

Otherwise the property is just defined, as follows:

property MyType myType

To manage backend objects:

  1. Select the Backends tab to view accessible backend objects.

  2. Select the (Add) button to add a backend object in the Add New C++ Backend dialog.
  3. In the Type field, select the type of the backend QObject to add.
  4. Select the Define object locally check box if the QObject is not registered as a singleton.
  5. Select OK to add the required import and to create the property for a non-singleton object.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.