Re: GLib critical message

The code in the attached file compiles and runs without errors or
warnings. It shows one way to inherit from an interface with a property.
But it's fairly ugly. Glib::Property<bool> redefines property
editing-canceled with g_object_class_install_property() instead of
g_object_class_override_property(), and it's done in the extra class
MyCellEditableX. It must be done before Gtk::CellEditable's constructor
is executed, or else the critical message shows up. More exactly,
g_object_class_install_property() must be called before

It would be nicer to use g_object_class_override_property(), but it
seems very difficult. If I have understood the rules of GObject
correctly, they say that g_object_class_override_property() must be
called _after_ g_type_add_interface_static(), but _before_ any object of
the registered type has been created. When a MyCellEditable object is
created, a C object is created (with g_object_newv()) in Glib::Object's
constructor, and g_type_add_interface_static() is called later, in
Gtk::CellEditable's constructor.


tor 2011-06-30 klockan 17:25 +0200 skrev Murray Cumming:

> Glib::Property<> (or PropertyProxy<>?) somehow registers the property in
> the GType system. Maybe it can be made to automatically override rather
> than register when appropriate.

#include <gtkmm/main.h>
#include <gtkmm/widget.h>
#include <gtkmm/celleditable.h>
#include <glibmm/property.h>
#include <glibmm/ustring.h>
#include <iostream>

class MyCellEditableX
: public Gtk::Widget
  MyCellEditableX() :
    m_editing_canceled(*this, "editing-canceled")

  Glib::Property<bool> m_editing_canceled;

}; // end class MyCellEditableX

class MyCellEditable
: public MyCellEditableX,
  public Gtk::CellEditable
  MyCellEditable() :
    //The GType name will actually be gtkmm__CustomObject_mycelleditable

}; // end class MyCellEditable

int main(int argc, char *argv[])
  Gtk::Main kit(argc, argv);

  MyCellEditable cell;

  // property_editing_canceled() is a member of Gtk::CellEditable.
  std::cout << "editing-canceled=" << cell.property_editing_canceled().get_value() << std::endl;
  std::cout << "editing-canceled=" << cell.property_editing_canceled().get_value() << std::endl;
  std::cout << "editing-canceled=" << cell.property_editing_canceled().get_value() << std::endl;

  return 0;

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