g_object_class_install_property: G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY not allowed

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

 



Hi,


I am dealing with a scenario where I want to have a property that can only be set and will be set at construction time.
Looking at the documentation, I thought that the appropriate combination of GParamFlags that should be used in this case is:  G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE

However, this doesn’t work as I am getting the critical error:

	Glib-GObject-CRITICAL **: g_object_class_install_property: assertion `(pspec->flags & G_PARAM_CONSTRUCT_ONLY) == 0` failed

This can be traced back to the following chunk of code in gobject.c

void
g_object_class_install_property (GObjectClass *class,
                                 guint         property_id,
                                 GParamSpec   *pspec)
{
  g_return_if_fail (G_IS_OBJECT_CLASS (class));
  g_return_if_fail (G_IS_PARAM_SPEC (pspec));

  if (CLASS_HAS_DERIVED_CLASS (class))
    g_error ("Attempt to add property %s::%s to class after it was derived", G_OBJECT_CLASS_NAME (class), pspec->name);

  class->flags |= CLASS_HAS_PROPS_FLAG;

  g_return_if_fail (pspec->flags & (G_PARAM_READABLE | G_PARAM_WRITABLE));
  if (pspec->flags & G_PARAM_WRITABLE)
    g_return_if_fail (class->set_property != NULL);
  if (pspec->flags & G_PARAM_READABLE)
    g_return_if_fail (class->get_property != NULL);
  g_return_if_fail (property_id > 0);
  g_return_if_fail (PARAM_SPEC_PARAM_ID (pspec) == 0);  /* paranoid */
  if (pspec->flags & G_PARAM_CONSTRUCT)
    g_return_if_fail ((pspec->flags & G_PARAM_CONSTRUCT_ONLY) == 0);       # this triggers the early return

Interestingly the next two lines of code appears to deal with exactly my case:

  if (pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY))
    g_return_if_fail (pspec->flags & G_PARAM_WRITABLE);

Any thoughts on this?

Thanks in advance,

Tom

_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-list




[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux