Re: Deriving from Gtk::ListStore

On Thu, 2004-11-25 at 22:17 +0100, Matthias wrote:
> Hi,
> say I want to derive my own model MyModel from Gtk::ListStore.
> Now this brings a couple of issues which aren't covered in the documentation.
> [At this point let me say, you're doing a great job on this library and I 
> really appreciate that, but the documentation is extremely lacking. Topics 
> like problems arising from deriving own widgets or even substantial things 
> like event handling are incomplete or not covered at all. When reading 
> through the documentation I have the impression it only scratches the surface 
> of a pretty complex GUI library, and unfortunately I have been proved right 
> so far. The examples are too trivial to be helpful and in some cases even 
> wrong.

These vague assertions are useless to us. You need to ask specific
questions and/or mention specific lack of documentation in bugzilla:

That's how gtkmm got this good, and that's how it gets better.

>  The zillions of typedefs used in functions don't make life easier].

I think you might be exagerating. Do you have a specific example and a
way to improve it?

> The problem is, that the model has to be instantiated using ListStore::create. 
> Unfortunately this returns a Glib::RefPtr to a ListStore object, and not to 
> an object of my derived type. Casting or using MyModel::create didn't help.

All classes that derive from Glib::Object must have protected
constructors but must have public create() methods that use those
constructors. That is true for your own classes as well as the gtkmm

> I have the impression that the MyModel specific parts are never initialized, 

Yes, your constructor is never called. Look at the ListStore::create()
implementation to see why - it knows nothing about your derived class.
create() is not part of the C++ language, and we have not extended the C
++ language.

I agree, this should be documented, and I'm surprised that it isn't
already. Luckily, deriving from Glib::Objects is fairly unusual.

> since ListStore::create only seems to initialize the base class part.
> This results in my program throwing "segmentation fault" errors at me when I 
> want to use my model.
> Well, I could try to explicitly create an instance of MyModel the standard 
> way. Unfortunately e.g. TreeView::set_model expects a Glib:RefPtr, so my 
> object is pretty useless because I can't pass it to that function.
> There seems to be no way to let a RefPtr point to my object either.
> So, what is the right approach to derive and create own models in gtkmm?

By the way, the treeview dnd example does this.

Murray Cumming
murrayc murrayc com

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