1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>Interface Properties</title>
6 <meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
7 <link rel="home" href="index.html" title="GObject Reference Manual">
8 <link rel="up" href="howto-interface.html" title="How to define and implement interfaces">
9 <link rel="prev" href="ch06s03.html" title="Interface definition prerequisites">
10 <link rel="next" href="howto-signals.html" title="How to create and use signals">
11 <meta name="generator" content="GTK-Doc V1.13 (XML mode)">
12 <link rel="stylesheet" href="style.css" type="text/css">
13 <link rel="preface" href="pr01.html" title="Introduction">
14 <link rel="part" href="pt01.html" title="Part I. Concepts">
15 <link rel="chapter" href="chapter-intro.html" title="Background">
16 <link rel="chapter" href="chapter-gtype.html" title="The GLib Dynamic Type System">
17 <link rel="chapter" href="chapter-gobject.html" title="The GObject base class">
18 <link rel="chapter" href="chapter-signal.html" title="The GObject messaging system">
19 <link rel="reference" href="rn01.html" title="API Reference">
20 <link rel="reference" href="rn02.html" title="Tools Reference">
21 <link rel="part" href="pt02.html" title="Part IV. Tutorial">
22 <link rel="chapter" href="howto-gobject.html" title="How to define and implement a new GObject">
23 <link rel="chapter" href="howto-interface.html" title="How to define and implement interfaces">
24 <link rel="chapter" href="howto-signals.html" title="How to create and use signals">
25 <link rel="part" href="pt03.html" title="Part V. Related Tools">
26 <link rel="chapter" href="tools-vala.html" title="Vala">
27 <link rel="chapter" href="tools-gob.html" title="GObject builder">
28 <link rel="chapter" href="tools-ginspector.html" title="Graphical inspection of GObjects">
29 <link rel="chapter" href="tools-refdb.html" title="Debugging reference count problems">
30 <link rel="chapter" href="tools-gtkdoc.html" title="Writing API docs">
31 <link rel="index" href="api-index-full.html" title="Index">
32 <link rel="index" href="api-index-deprecated.html" title="Index of deprecated symbols">
33 <link rel="index" href="api-index-2-2.html" title="Index of new symbols in 2.2">
34 <link rel="index" href="api-index-2-4.html" title="Index of new symbols in 2.4">
35 <link rel="index" href="api-index-2-6.html" title="Index of new symbols in 2.6">
36 <link rel="index" href="api-index-2-8.html" title="Index of new symbols in 2.8">
37 <link rel="index" href="api-index-2-10.html" title="Index of new symbols in 2.10">
38 <link rel="index" href="api-index-2-12.html" title="Index of new symbols in 2.12">
39 <link rel="index" href="api-index-2-14.html" title="Index of new symbols in 2.14">
40 <link rel="index" href="api-index-2-18.html" title="Index of new symbols in 2.18">
41 <link rel="index" href="api-index-2-22.html" title="Index of new symbols in 2.22">
42 <link rel="index" href="api-index-2-24.html" title="Index of new symbols in 2.24">
44 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
45 <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle">
46 <td><a accesskey="p" href="ch06s03.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
47 <td><a accesskey="u" href="howto-interface.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
48 <td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
49 <th width="100%" align="center">GObject Reference Manual</th>
50 <td><a accesskey="n" href="howto-signals.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
52 <div class="sect1" title="Interface Properties">
53 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
54 <a name="howto-interface-properties"></a>Interface Properties</h2></div></div></div>
56 Starting from version 2.4 of GLib, GObject interfaces can also have
57 properties. Declaration of the interface properties is similar to
58 declaring the properties of ordinary GObject types as explained in
59 <a class="xref" href="gobject-properties.html" title="Object properties">the section called “Object properties”</a>,
60 except that <code class="function"><a class="link" href="gobject-The-Base-Object-Type.html#g-object-interface-install-property" title="g_object_interface_install_property ()">g_object_interface_install_property</a></code> is used to
61 declare the properties instead of <code class="function"><a class="link" href="gobject-The-Base-Object-Type.html#g-object-class-install-property" title="g_object_class_install_property ()">g_object_class_install_property</a></code>.
64 To include a property named 'name' of type <span class="type">string</span> in the
65 <span class="type">maman_ibaz</span> interface example code above, we only need to
67 <sup>[<a name="id650412" href="#ftn.id650412" class="footnote">12</a>]</sup>
68 line in the <code class="function">maman_ibaz_base_init</code>
69 <sup>[<a name="id650426" href="#ftn.id650426" class="footnote">13</a>]</sup>
72 <pre class="programlisting">
74 maman_ibaz_base_init (gpointer g_iface)
76 static gboolean is_initialized = FALSE;
80 g_object_interface_install_property (g_iface,
81 g_param_spec_string ("name",
83 "Name of the MamanIbaz",
86 is_initialized = TRUE;
93 One point worth noting is that the declared property wasn't assigned an
94 integer ID. The reason being that integer IDs of properties are used
95 only inside the get and set methods and since interfaces do not
96 implement properties, there is no need to assign integer IDs to
100 An implementation shall declare and define it's properties in the usual
101 way as explained in <a class="xref" href="gobject-properties.html" title="Object properties">the section called “Object properties”</a>, except for one
102 small change: it must declare the properties of the interface it
103 implements using <code class="function"><a class="link" href="gobject-The-Base-Object-Type.html#g-object-class-override-property" title="g_object_class_override_property ()">g_object_class_override_property</a></code>
104 instead of <code class="function"><a class="link" href="gobject-The-Base-Object-Type.html#g-object-class-install-property" title="g_object_class_install_property ()">g_object_class_install_property</a></code>.
105 The following code snippet shows the modifications needed in the
106 <span class="type">MamanBaz</span> declaration and implementation above:
108 <pre class="programlisting">
112 GObject parent_instance;
114 gint instance_member;
126 maman_baz_set_property (GObject *object,
131 MamanBaz *baz = MAMAN_BAZ (object);
137 g_free (baz->name);
138 baz->name = g_value_dup_string (value);
142 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
148 maman_baz_get_property (GObject *object,
153 MamanBaz *baz = MAMAN_BAZ (object);
158 g_value_set_string (value, baz->name);
162 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
168 maman_baz_class_init (MamanBazClass *klass)
170 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
172 gobject_class->set_property = maman_baz_set_property;
173 gobject_class->get_property = maman_baz_get_property;
175 g_object_class_override_property (gobject_class, PROP_NAME, "name");
181 <div class="footnotes">
182 <br><hr width="100" align="left">
183 <div class="footnote"><p><sup>[<a name="ftn.id650412" href="#id650412" class="para">12</a>] </sup>
184 That really is one line extended to six for the sake of clarity
186 <div class="footnote"><p><sup>[<a name="ftn.id650426" href="#id650426" class="para">13</a>] </sup>
187 The <code class="function"><a class="link" href="gobject-The-Base-Object-Type.html#g-object-interface-install-property" title="g_object_interface_install_property ()">g_object_interface_install_property</a></code>
188 can also be called from <code class="function">class_init</code> but it must
189 not be called after that point.
195 Generated by GTK-Doc V1.13</div>