Method

GObjectObjectbind_property

Declaration

GBinding*
g_object_bind_property (
  GObject* source,
  const gchar* source_property,
  GObject* target,
  const gchar* target_property,
  GBindingFlags flags
)

Description

Creates a binding between source_property on source and target_property on target.

Whenever the source_property is changed the target_property is updated using the same value. For instance:

  g_object_bind_property (action, "active", widget, "sensitive", 0);

Will result in the “sensitive” property of the widget GObject instance to be updated with the same value of the “active” property of the action GObject instance.

If flags contains G_BINDING_BIDIRECTIONAL then the binding will be mutual: if target_property on target changes then the source_property on source will be updated as well.

The binding will automatically be removed when either the source or the target instances are finalized. To remove the binding without affecting the source and the target you can just call g_object_unref() on the returned GBinding instance.

Removing the binding by calling g_object_unref() on it must only be done if the binding, source and target are only used from a single thread and it is clear that both source and target outlive the binding. Especially it is not safe to rely on this if the binding, source or target can be finalized from different threads. Keep another reference to the binding and use g_binding_unbind() instead to be on the safe side.

A GObject can have multiple bindings.

Available since:2.26

Parameters

source_property const gchar*
 

The property on source to bind.

 The data is owned by the caller of the function.
 The string is a NUL terminated UTF-8 string.
target GObject
 

The target GObject.

 The data is owned by the caller of the function.
target_property const gchar*
 

The property on target to bind.

 The data is owned by the caller of the function.
 The string is a NUL terminated UTF-8 string.
flags GBindingFlags
 

Flags to pass to GBinding.

Return value

Returns: GBinding
 

The GBinding instance representing the binding between the two GObject instances. The binding is released whenever the GBinding reference count reaches zero.

 The data is owned by the instance.