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]