Re: Doing introspection on a GObject



On Tue, 2008-07-08 at 13:02 +0200, Andreas Sliwka wrote:
> Greetings,
>   I'd like to query a Gobject for its properties. Browsing through the
> header files I found g_object_class_list_properties(), which takes a
> GObjectClass as first parameter. Now how do I get this GObjectClass
> from GObject? Is this possible at all

yes, of course:

  GParamSpec **pspecs;
  GObjectClass *object_class;
  gint n_pspecs;

  object_class = G_OBJECT_GET_CLASS (object_instance);

  pspecs = g_object_class_list_properties (object_class, &n_pspecs);
  for (i = 0; i < n_pspecs; i++)
    {
      GParamSpec *pspec = pspecs[i];

      g_print ("Objects of type %s have the %s property\n",
               G_OBJECT_TYPE_NAME (some_instance),
               pspec->name);
    }
  g_free (pspecs);

ciao,
 Emmanuele.

-- 
Emmanuele Bassi,
W: http://www.emmanuelebassi.net
B: http://log.emmanuelebassi.net



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]