diff --git a/docs/reference/gobject/tut_gobject.xml b/docs/reference/gobject/tut_gobject.xml
index b34441b17..221b35b6f 100644
--- a/docs/reference/gobject/tut_gobject.xml
+++ b/docs/reference/gobject/tut_gobject.xml
@@ -495,14 +495,14 @@ void g_object_run_dispose (GObject *object);
One of GObject's nice features is its generic get/set mechanism for object
properties. When an object
is instantiated, the object's class_init handler should be used to register
- the object's properties with g_object_class_install_property
+ the object's properties with g_object_class_install_properties
(implemented in gobject.c).
The best way to understand how object properties work is by looking at a real example
on how it is used:
-
+
/************************************************/
/* Implementation */
/************************************************/
@@ -512,9 +512,13 @@ enum
PROP_0,
PROP_MAMAN_NAME,
- PROP_PAPA_NUMBER
+ PROP_PAPA_NUMBER,
+
+ N_PROPERTIES
};
+static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
+
static void
maman_bar_set_property (GObject *object,
guint property_id,
@@ -572,30 +576,29 @@ static void
maman_bar_class_init (MamanBarClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- GParamSpec *pspec;
gobject_class->set_property = maman_bar_set_property;
gobject_class->get_property = maman_bar_get_property;
- pspec = g_param_spec_string ("maman-name",
- "Maman construct prop",
- "Set maman's name",
- "no-name-set" /* default value */,
- G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
- g_object_class_install_property (gobject_class,
- PROP_MAMAN_NAME,
- pspec);
+ obj_properties[PROP_NAME] =
+ g_param_spec_string ("maman-name",
+ "Maman construct prop",
+ "Set maman's name",
+ "no-name-set" /* default value */,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
- pspec = g_param_spec_uchar ("papa-number",
- "Number of current Papa",
- "Set/Get papa's number",
- 0 /* minimum value */,
- 10 /* maximum value */,
- 2 /* default value */,
- G_PARAM_READWRITE);
- g_object_class_install_property (gobject_class,
- PROP_PAPA_NUMBER,
- pspec);
+ obj_properties[PROP_NUMBER] =
+ g_param_spec_uchar ("papa-number",
+ "Number of current Papa",
+ "Set/Get papa's number",
+ 0 /* minimum value */,
+ 10 /* maximum value */,
+ 2 /* default value */,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_properties (gobject_class,
+ N_PROPERTIES,
+ obj_properties);
}
/************************************************/
@@ -613,7 +616,7 @@ g_value_set_char (&val, 11);
g_object_set_property (G_OBJECT (bar), "papa-number", &val);
g_value_unset (&val);
-
+
The client code just above looks simple but a lot of things happen under the hood:
diff --git a/docs/reference/gobject/tut_howto.xml b/docs/reference/gobject/tut_howto.xml
index 9d592b8bd..6564d8b92 100644
--- a/docs/reference/gobject/tut_howto.xml
+++ b/docs/reference/gobject/tut_howto.xml
@@ -341,26 +341,37 @@ maman_bar_init (MamanBar *self)
. Make sure that these properties use a construct only
GParamSpec by setting the param spec's flag field to G_PARAM_CONSTRUCT_ONLY: this helps
GType ensure that these properties are not set again later by malicious user code.
-
+
+enum {
+ PROP_0,
+
+ PROP_MAMAN,
+
+ N_PROPERTIES
+};
+
+static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
+
static void
bar_class_init (MamanBarClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- GParamSpec *pspec;
gobject_class->set_property = bar_set_property;
gobject_class->get_property = bar_get_property;
- pspec = g_param_spec_string ("maman",
- "Maman construct prop",
- "Set maman's name",
- "no-name-set" /* default value */,
- G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
- g_object_class_install_property (gobject_class,
- PROP_MAMAN,
- pspec);
+ obj_properties[PROP_MAMAN] =
+ g_param_spec_string ("maman",
+ "Maman construct prop",
+ "Set maman's name",
+ "no-name-set" /* default value */,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
+
+ g_object_class_install_properties (gobject_class,
+ N_PROPERTIES,
+ obj_properties);
}
-
+
If you need this, make sure you can build and run code similar to the code shown above. Make sure
your construct properties can set correctly during construction, make sure you cannot set them
afterwards and make sure that if your users do not call g_object_new