IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

Connections QML Type

Describes generalized connections to signals.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

Connections QML Type

  • Import Statement: import QtQml

  • Group: Connections is part of qtquick-interceptors

Detailed Description

A Connections object creates a connection to a QML signal.

When connecting to signals in QML, the usual way is to create an "on<Signal>" handler that reacts when a signal is received, like this:

 
Sélectionnez
MouseArea {
    onClicked: (mouse)=&gt; { foo(mouse) }
}

However, it is not possible to connect to a signal in this way in some cases, such as when:

  • Multiple connections to the same signal are required

  • Creating connections outside the scope of the signal sender

  • Connecting to targets not defined in QML

When any of these are needed, the Connections type can be used instead.

For example, the above code can be changed to use a Connections object, like this:

 
Sélectionnez
MouseArea {
    Connections {
        function onClicked(mouse) { foo(mouse) }
    }
}

More generally, the Connections object can be a child of some object other than the sender of the signal:

 
Sélectionnez
MouseArea {
    id: area
}
// ...
 
Sélectionnez
Connections {
    target: area
    function onClicked(mouse) { foo(mouse) }
}

For backwards compatibility you can also specify the signal handlers without function, like you would specify them directly in the target object. This is not recommended. If you specify one signal handler this way, then all signal handlers specified as function in the same Connections object are ignored.

See Also

See also Qt QML

Property Documentation

 

[since 5.7] enabled : bool

This property holds whether the item accepts change events.

By default, this property is true.

This property was introduced in Qt 5.7.

ignoreUnknownSignals : bool

Normally, a connection to a non-existent signal produces runtime errors.

If this property is set to true, such errors are ignored. This is useful if you intend to connect to different types of objects, handling a different set of signals for each object.

target : QtObject

This property holds the object that sends the signal.

If this property is not set, the target defaults to the parent of the Connection.

If set to null, no connection is made and any signal handlers are ignored until the target is not null.

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+