RE: [gtkmm] TreeView Model, SEGV on append
- From: "Ohrnberger, Erik" <erik_ohrnberger dme net>
- To: "'gtkmm-list gnome org'" <gtkmm-list gnome org>
- Subject: RE: [gtkmm] TreeView Model, SEGV on append
- Date: Tue, 11 Nov 2003 12:53:27 -0500
Just a question on construction means and order for the Gtkmm objects that
I'm using and sub classing from.
If I follow the order of construction from beginning to end, I see that some
are dynamic and some are automatic. What I mean that in some cases to
create a new object instance I do this:
Gtk::Notebook* tmpNotebook == NULL;
tmpNotebook = manage( new Gtk::Notebook() );
<containing widget>->add( *tmpNotebook );
tmpNotebook->show();
In other cases, I declare the object as part of a class:
class MyClass : public Gtk::VBox
{
.....
private:
Gtk::Notebook MyNotebook;
};
And in this class' CTOR:
MyClass::MyClass() : Gtk::VBox()
{
add( &MyNotebook );
MyNotebook.show();
}
Are both of these means for constructing Gtk containing and Gtk subclassed
object instances valid?
Can both of these methods be used at the same time? What I mean to say is
that a containing class may be dynamic, while some of it's contained widgets
may be either dynamic or automatic (second example).
Is there any particular advantage in doing it one way over the other? If
so, what would it be? Is it just for the sake of consistency?
Thanks,
Erik.
> -----Original Message-----
> From: Jeff Gavin [mailto:jeff ezclick net]
> Sent: Wednesday, October 29, 2003 3:54 PM
> To: Ohrnberger, Erik
> Cc: 'gtkmm-list gnome org'
> Subject: Re: [gtkmm] TreeView Model, SEGV on append
>
>
> Ohrnberger, Erik wrote:
> > Jeff,
> > Digging a little more into this confirms that
> pMoldListModel is NULL
> > in the method that is trying to use it to append a new line.
> >
> > However, pMoldListModel is initialized in the CTOR of
> the containing
> > class, which makes me think that it's somehow loosing it's
> state between the
> > CTOR and the method that wants to use it to add new items
> to the list.
> >
> > In addition, I've made sure that on this containing class' CTOR,
> > that.....
> >
> > MoldList::MoldList() :
> > ScrolledWindow(), // containing class is
> subclass of
> > ...
> > tvMTBList(), // TreeView widget
> > pMTBListModel() // Model.
> >
> > and in the CTOR, there is code that news the columns
> > pCols = new MoldListCols();
>
> What is the scope of pCols? Your problem makes me think of
> the time I
> created an object inside the constructor, and when the constructor
> ended, the object's callbacks were deleted! The problem was
> my variable
> (a button widget) was declared INSIDE the constructor, and I
> attached a
> callback to it. When the constructor ended, the SigC class detected
> that the variable was now out of scope AND REMOVED THE
> CALLBACKS that I
> just created!
>
> >
> > creates the model:
> > pMoldListModel = ListStore::create( *pCols );
> >
> > also appends columns to the treeview, adds the treeview
> widget to
> > the containing class (ScrolledWindow) and show it.
> >
> > The workaround that I have in place now is to re-create
> the model
> > each time that I want to add a new item to the list
> completely populating
> > the list from scratch.
> >
> > However, this is less than satisfying.
> >
> > Are there any known problems with not using dynamic
> objects for the
> > ScrolledWindow, the TreeView, or the TreeView model? I've
> decld them as
> > automatic inside of the class as data members.
>
> Erik,
>
> I'm not a C++ expert, but I can describe how I handle
> treeview widgets
> in the code I write. Maybe this will help you decide how
> best resolve
> your issue.
>
> I use glade-2 to create my user interface. I think it's easier to
> create a glade-2 project for each window of the system. In this way,
> there can be a C++ class (the window class) associated with
> each glade
> file. The constructor of the window class reads the glade
> XML, and gets
> the widget pointers for each widget on the window.
>
> In my system, each Treeview widget has it's own 'controller'
> class that
> manages the contents of the treeview (this includes the model). So
> everytime I create a window that contains a treeview object, then two
> objects are created in the window class: a treeview object
> (read in from
> the glade XML file), and it's associated controller object.
>
> A description of the files and what they are for:
>
> The controller of a treeview that displays a list of products:
> wcProductList.h
> wcProductList.cc
>
> A class that creates a window that shows products:
> winProducts.h
> winProducts.cc
>
> The glade file that holds the user interface:
> winProducts.glade
>
> Here are some code snip examples from my project:
>
> // This is the tv widget controller header:
>
> class wcProductList : public SigC::Object
> {
> public:
>
> wcProductList(Gtk::TreeView *w);
>
> void insert(const Glib::ustring &code,
> const Glib::ustring &name,
> const Glib::ustring &quantity);
>
> void clear();
>
> class ColumnModel : public Gtk::TreeModel::ColumnRecord
> {
> public:
> ColumnModel (void);
>
> Gtk::TreeModelColumn<Glib::ustring> code;
> Gtk::TreeModelColumn<Glib::ustring> name;
> Gtk::TreeModelColumn<Glib::ustring> quantity;
> };
>
> private:
> ColumnModel columns;
> Gtk::TreeView *m_TreeView;
> Glib::RefPtr<Gtk::ListStore> m_refTreeModel;
>
> void on_TreeView_cursor_changed(void);
> };
>
> Here is the constructor for the controller:
>
> wcProductList::wcProductList(Gtk::TreeView *w)
> {
> // 'w' is the treeview object that I'm controlling!
> m_TreeView = w;
>
> m_TreeView->signal_cursor_changed().connect
> (SigC::slot(*this, &wcProductList::on_TreeView_cursor_changed));
>
> // Create the Tree model:
> m_refTreeModel = Gtk::ListStore::create(columns);
> m_TreeView->set_model(m_refTreeModel);
>
> // Add the TreeView's visible columns (columns.code is hidden):
> m_TreeView->append_column("Product Name", columns.name);
> m_TreeView->append_column("Quantity", columns.quantity);
> }
>
> and of course the column model construction:
>
> wcProductList::ColumnModel::ColumnModel()
> {
> Gtk::TreeModel::ColumnRecord::add(code);
> Gtk::TreeModel::ColumnRecord::add(name);
> Gtk::TreeModel::ColumnRecord::add(quantity);
> }
>
> and FINALLY, the implementation in the construction of the top level
> window class that is displaying the actual treeview:
>
> winProducts::winProducts (Gtk::Container * parent)
> {
> //
> // * * * * * * * * User Interface Setup * * * * * * * * * * * * * *
> //
>
> m_refGlade = Gnome::Glade::Xml::create ("winProducts.glade");
> m_refGlade->reparent_widget ("vbox1", *parent);
>
> <... snip ...>
>
> // HERE are the two objects I mention in the mail:
> // 1. tvCurrentProductList (the treeview widget).
> // 2. wcCurrentProductList (#1's controller).
>
> // Read the tv widget from the glade file...
> tvCurrentProductList = 0;
> m_refGlade->get_widget
> ("tvCurrentProductList", tvCurrentProductList);
>
> // Attach the tv widget to it's controller...
> wcCurrentProductList =
> new wcProductList(tvCurrentProductList);
>
> <... snip ...>
>
> };
>
>
> >
> > Thanks,
> > Erik.
> >
> >
> >>-----Original Message-----
> >>From: Jeff Gavin [mailto:jeff ezclick net]
> >>Sent: Friday, October 24, 2003 5:15 PM
> >>To: Ohrnberger, Erik
> >>Cc: 'gtkmm-list gnome org'
> >>Subject: Re: [gtkmm] TreeView Model, SEGV on append
> >>
> >>
> >>Ohrnberger, Erik wrote:
> >>
> >>>I'm hoping that someone can give me a pointer on tracking
> >>
> >>the issue down
> >>
> >>>with my code.
> >>>
> >>>I build a scrolled windows, attach a treeview to it, create the
> >>>ListStore::create to create the model, and set this model
> >>
> >>to the treeview.
> >>
> >>>Next, I append my columns to the treeview and try and
> >>
> >>perform an append on
> >>
> >>>the model. It's right on the statement below:
> >>>
> >>> TreeModel::Row row = *( pMoldListModel->append() );
> >>
> >>To help isolate this type of error, split the line:
> >>
> >> TreeModel::Row row;
> >> row = *( pMoldListModel->append() );
> >>
> >>to help determine where the problem if the problem is in the
> >>construction of 'row' or the call to append.
> >>
> >>Without seeing the rest of the code, my bet is on
> pMoldListModel not
> >>being initialized.
> >>
> >>
> >>
> >>
> >>>Where the program gets a segv and crashes the program inside of the
> >>>gtkmm-2.2.5. As it's crashing right inside this call into
> >>
> >>the libraries,
> >>
> >>>what do you think is went wrong? What should I do to track
> >>
> >>this further
> >>
> >>>down?
> >>>
> >>>Thanks,
> >>> Erik.
> >>> Erik_Ohrnberger<-at->DME.net
> >>>
> >>>_______________________________________________
> >>>gtkmm-list mailing list
> >>>gtkmm-list gnome org
> >>>http://mail.gnome.org/mailman/listinfo/gtkmm-list
> >>>
> >>
> >>
> >
>
>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]