Re: custom treemodel?
- From: "Andrew E. Makeev" <andrew solvo ru>
- To: Jonathon Jongsma <jonathon jongsma gmail com>
- Cc: Murray Cumming <murrayc murrayc com>, gtkmm-list <gtkmm-list gnome org>
- Subject: Re: custom treemodel?
- Date: Fri, 19 May 2006 18:43:12 +0400
Jonathon Jongsma wrote:
> In fact i have a skeleton like this implemented to play around with,
> but I can't get it to instantiate. When I call the
> MyListModel::create() function, I keep getting errors like this:
>
> glibmm-CRITICAL **: Glib::Interface::Interface(const
> Glib::Interface_Class&): assertion `gobject_ != 0' failed
Maybe you need to call the Glib::Object (or maybe ObjectBase, I forget)
constructor differently, if the example does that. Remember our
discussion
about virtual inheritance.
Well, I call it exactly the same way as the example does it. The main
difference is of course that I'm not actually instantiating that
class, but one derived from it.
Glib interfaces are implemented by GObjects. That's just how the GObject
type system works. So we need a GObject type, and each of our class
instances will need an instance of that GObject type.
Right. Perhaps I just need to bite the bullet and brush up on some
GObject fundamentals. gtkmm is very good about hiding most of the
GObject ugliness, but it seems like this is one instance where I may
need some additional background.
> Or should I be doing the GObject type registration in the most derived
> class (MyListModel) instead of CustomTreeModel? Or is my approach
> just flawed in some basic way?
Yes, I suspect that you might need to call the Object constructor in the
most derived class. And that is where you are doing the type
registration,
I think.
OK, here are some results of some trial-and-error experimentation.
See if you can make sense of them :)
No Warnings:
===========
CustomTreeModel : public Gtk::TreeModel
MyListModel : public CustomTreeModel<>, virtual public Glib::Object
- calls Object, ObjectBase constructor
CustomTreeModel : public Gtk::TreeModel, virtual public Glib::Object
- calls Object, ObjectBase constructor
MyListModel : public CustomTreeModel<>, virtual public Glib::Object
- calls Object, ObjectBase constructor
CustomTreeModel : public Gtk::TreeModel, virtual public Glib::Object
- calls Object, ObjectBase constructor
MyListModel : public CustomTreeModel<>, virtual public Glib::Object
CustomTreeModel : public Gtk::TreeModel, virtual public Glib::Object
- calls Object, ObjectBase constructor
MyListModel : public CustomTreeModel<>
Gives Warning:
============
CustomTreeModel : public Gtk::TreeModel, public Glib::Object
- calls Object, ObjectBase constructor
MyListModel : public CustomTreeModel<>
CustomTreeModel : public Gtk::TreeModel
MyListModel : public CustomTreeModel<>, public Glib::Object
- calls Object, ObjectBase constructor
Error, crash
============
CustomTreeModel : public Gtk::TreeModel, public Glib::Object
- calls Object, ObjectBase constructor
MyListModel : public CustomTreeModel<>, public Glib::Object
- calls Object, ObjectBase constructor
So it seems that when I use virtual inheritance, the warnings go away.
But I can't quite figure out why... I haven't gotten around to
implementing enough of the class to see whether the model actually
works correctly, but the warnings are gone. Now the question -- which
of the four non-warning choices is correct, if any?
That is may way of creating custom models:
class CommonModel // class with common data handling and sorting
methods for my data-container
{...}
class DataListTreeModel
: public Glib::Object
, public Gtk::TreeModel
, public Gtk::TreeSortable
, public CommonModel
{...}
class BROWSER_DLL_EXP_IMP DataTreeTreeModel
: public Glib::Object
, public Gtk::TreeModel
, public Gtk::TreeSortable
, public CommonModel
{...}
CommonModel::CommonModel( DataSet* ds )
{...}
DataListTreeModel::DataListTreeModel( DataSet* ds )
: Glib::ObjectBase( typeid( DataListTreeModel ) )
, Glib::Object()
, CommonModel( ds )
{...}
DataTreeTreeModel::DataTreeTreeModel( DataSet* ds )
: Glib::ObjectBase( typeid( DataTreeTreeModel ) )
, Glib::Object()
, CommonModel( ds )
{...}
there is no warning nor crash.
Regards,
-andrew
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]