GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Jul 29, 2014 8:52 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Gtk::TreeView segmentation fault
PostPosted: Sun Mar 02, 2008 8:15 pm 
Offline

Joined: Sun Mar 02, 2008 7:49 pm
Posts: 1
Hi, i'm using gtk + glade + c++, my program compiles without errors,
Code:
gcc `pkg-config gtkmm-2.4 --libs --cflags` `pkg-config --libs --cflags libglademm-2.4` -ggdb main.cc -o main

but when i run it i got "Segmentation fault (core dumped)" :-/

gdb output:
Code:
Starting program: /home/marcin/Projects/gtk2/src/main
[Thread debugging using libthread_db enabled]
[New Thread -1225648448 (LWP 11070)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1225648448 (LWP 11070)]
0xb7eb996d in Gtk::TreeView::set_model (this=0x0, model=@0xbfaef920)
    at treeview.cc:1289
1289    treeview.cc: No such file or directory.
        in treeview.cc
Current language:  auto; currently c++
(gdb) backtrace
#0  0xb7eb996d in Gtk::TreeView::set_model (this=0x0, model=@0xbfaef920)
    at treeview.cc:1289
#1  0x0804f229 in wndOkno::wndOkno ()
#2  0x08052d93 in Gnome::Glade::Xml::get_widget_derived<wndOkno> ()
#3  0x0804fe58 in main ()
(gdb) frame 0
#0  0xb7eb996d in Gtk::TreeView::set_model (this=0x0, model=@0xbfaef920)
    at treeview.cc:1289
1289    in treeview.cc

so the problem is in Gtk::TreeView::set_model (i think so).

main.cc
Code:
#include <libglademm.h>
#include <libglademm/xml.h>
#include "gtk2.h"
#include "gtk2.cc"

int main (int argc, char *argv[])
{
   Gtk::Main kit(argc, argv);

   //Load the Glade file and instiate its widgets:
   Glib::RefPtr<Gnome::Glade::Xml> refXml =
   Gnome::Glade::Xml::create("gtk2.glade");

   wndOkno *okno;
   refXml->get_widget_derived("window1", okno);
   
   Gtk::Main::run(*okno);
   return 0;
}

gtk2.h :
Code:
#include <gtkmm.h>

class wndOkno : public Gtk::Window {
  public:
    wndOkno(BaseObjectType* base_object,
  const Glib::RefPtr<Gnome::Glade::Xml>& glade_xml);
    virtual ~wndOkno();

  // signal handlers
  private:
   virtual void btn_add_row_clicked();
   virtual void btn_exit_clicked();
   virtual void btn_srednia_clicked();
   
   class ModelColumns: public Gtk::TreeModel::ColumnRecord {
     public:
       // konstruktor ModelColumns dodaje kolumny do modelu kolumn
       ModelColumns() {
      add(c0);
// i've cuted that part
       }
       // typy danych w komórkach kolumn
      Gtk::TreeModelColumn<unsigned int> c0;
//this part also ;-)
   };
   
   ModelColumns mc;

   // widgety potomne

   Gtk::Button *btn_exit;
   Gtk::Button *btn_add_row;
   Gtk::Entry *entry1;
   Gtk::TreeView *tv;
   Glib::RefPtr<Gtk::ListStore> tmdl;
};


and gtk2.cc
Code:
#include <iostream>
#include "gtk2.h"
#include <libglademm.h>
#include <libglademm/xml.h>

wndOkno::wndOkno(BaseObjectType* base_object,
  const Glib::RefPtr<Gnome::Glade::Xml>& glade_xml) : Gtk::Window(base_object) {

   //Load the Glade file and instiate its widgets:
   Glib::RefPtr<Gnome::Glade::Xml> refXml =
   Gnome::Glade::Xml::create("gtk2.glade");

   // stworzenie modelu danych na podstawie modelu kolumn
[b]probably here is error:[/b]   tmdl = Gtk::ListStore::create(mc);

   // kojarzymy widok z modelem - czyli wiazemy dane z tym co widac na ekranie
[b]or here:[/b]   tv->set_model(tmdl);
   
   // dodajemy do widoku listy kolumne z numerem           
   tv->append_column_editable("c0", mc.c0);
//part cuted


   refXml->get_widget("button3", btn_exit);
   btn_exit->signal_clicked().connect(sigc::mem_fun(*this,&wndOkno::btn_exit_clicked));
   
   
   refXml->get_widget("button1", btn_add_row);
   btn_add_row->signal_clicked().connect(sigc::mem_fun(*this, &wndOkno::btn_add_row_clicked));


   refXml->get_widget("button1", btn_srednia);
   btn_add_row->signal_clicked().connect(sigc::mem_fun(*this,&wndOkno::btn_srednia_clicked));


   refXml->get_widget("entry1", entry1);   

   
    // wczytanie widoku z pliku
    refXml->get_widget("treeview1", tv);

}

wndOkno::~wndOkno() {

}

void wndOkno::btn_add_row_clicked(){
   // stworzenie nowego rzedu w modelu danych i uzyskanie referencji do niego
   Gtk::TreeModel::Row rw = *(tmdl->append());
   // nadanie wartosci rw[mc.m_col_id] = 1;
   rw[mc.c0] = (unsigned int)rand()%100+1;
//part cuted
}

void wndOkno::btn_exit_clicked(){
   std::cout<<"Kończę super program, damn! ;-)"<<std::endl;
   Gtk::Main::quit();
}
maybe someone know how to correct it :-/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group