segfault on liststore append()
- From: "Jeremy Shivers" <shivers53 hotmail com>
- To: gtkmm-list gnome org
- Subject: segfault on liststore append()
- Date: Sat, 05 Mar 2005 15:29:27 +0000
I am trying to have one window add data to a treeview column in a different
window and I am getting a segfault when the list store reference pointer
tries to append(). Below is the code used.
window1.h
---------
#include <gtkmm.h>
class CWindow1 : public Gtk::Window
{
public:
CWindow1(Gtk::Window *parent);
private:
class CColumnRecord : public Gtk::TreeModelColumnRecord
{
public:
CColumnRecord() { add(Column1); }
Gtk::TreeModelColumn<Glib::ustring> Column1;
};
Glib::RefPtr<Gtk::ListStore> _RPListStore;
const CColumnRecord _ColumnRecord;
Gtk::ScrolledWindow *_ScrolledWindow;
Gtk::TreeView *_TreeView;
virtual void onAddColumnData();
};
window1.cpp
-----------
#include <sigc++/sigc++.h>
#include "window1.h"
using namespace Gdk;
using namespace Gtk;
CWindow1::CWindow1() : Window(Gtk::WINDOW_TOPLEVEL)
{
set_title("Window1");
set_size_request(500, 500);
set_resizable(false);
set_modal(true);
set_position(WIN_POS_CENTER);
set_type_hint(WINDOW_TYPE_HINT_NORMAL);
_ScrolledWindow = manage(new ScrolledWindow());
_TreeView = manage(new TreeView());
_TreeView->set_flags(CAN_FOCUS);
_TreeView->set_headers_visible(true);
_TreeView->set_rules_hint(true);
_TreeView->set_reorderable(true);
_TreeView->set_enable_search(true);
_ScrolledWindow->set_flags(CAN_FOCUS);
_ScrolledWindow->set_shadow_type(SHADOW_IN);
_ScrolledWindow->set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC);
_ScrolledWindow->set_placement(CORNER_TOP_LEFT);
_ScrolledWindow->add(*_TreeView);
add(*_ScrolledWindow);
_RPListStore = ListStore::create(_ColumnRecord);
_TreeView->set_model(_RPListStore);
int columnCount = _TreeView->append_column("Column1",
_ColumnRecord.Column1);
TreeViewColumn *tvc = _TreeView->get_column(columnCount - 1);
if (tvc)
{
tvc->set_resizable(true);
tvc->set_clickable(true);
tvc->set_sizing(TREE_VIEW_COLUMN_AUTOSIZE);
}
_ScrolledWindow->show();
_TreeView->show();
}
void CWindow1::onAddColumnData()
{
// segfaults here when called from window2
TreeRow row = *(_RPListStore->append());
}
window2.h
---------
#include <sigc++/sigc++.h>
#include <gtkmm.h>
class CWindow1;
class CWindow2 : public Gtk::Window
{
public:
CWindow2(Gtk::Window *parent);
private:
Gtk::Button *_Button;
virtual void onButtonClicked();
sigc::signal<void> _ButtonClicked;
CWindow1 *_Parent;
};
window2.cpp
-----------
#include "window2.h"
#include "window1.h"
using namespace Gtk;
using namespace Gdk;
using namespace Glib;
CWindow2::CWindow2(Window *parent) : Window(Gtk::WINDOW_TOPLEVEL)
{
_Parent = (CWindow1 *)parent;
set_title("Window2");
set_size_request(500, 500);
set_resizable(false);
set_modal(true);
set_position(WIN_POS_CENTER);
set_transient_for(*parent);
set_type_hint(WINDOW_TYPE_HINT_NORMAL);
_Button = manage(new Button("Click Me"));
_Button->set_flags(CAN_FOCUS);
_Button->set_flags(CAN_DEFAULT);
_Button->set_relief(RELIEF_NORMAL);
add(*_Button);
_Button->show();
_Button->signal_clicked().connect(sigc::mem_fun(*this,
&CWindow2::onButtonClicked), false);
// Doesn?t compile this way. Must do it the way below
//_ButtonClicked.connect(sigc::mem_fun(*_Parent,
&CWindow1::onAddColumnData));
sigc::slot<void> s = sigc::mem_fun(*_Parent, &CWindow1::onAddColumnData);
_ButtonClicked.connect(s);
}
void CWindow2::onButtonClicked()
{
_ButtonClicked.emit();
hide();
}
main.cpp
--------
#include <gtkmm/main.h>
#include "window1.h"
int main(int argc, char *argv[])
{
Gtk::Main m(&argc, &argv);
CWindow1 *w = new CWindow1();
m.run(*w);
delete w;
return 0;
}
Am I doing something wrong, or is there a better way of accomplishing this?
gtk 2.6.0
glib 2.6.0
gtkmm 2.4
glibmm 2.4
libsigc++ 2.0.9
Thanks in advance
visy
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]