GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Gtk::TreeView segmentation fault

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
marcin



Joined: 02 Mar 2008
Posts: 1

PostPosted: Sun Mar 02, 2008 8:15 pm    Post subject: Gtk::TreeView segmentation fault Reply with quote

Hi, i'm using gtk + glade + c++, my program compiles without errors,
Code: (Plaintext)
1
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: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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: (C++)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#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: (C++)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#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: (C++)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#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&#324;cz&#281; super program, damn! ;-)"<<std::endl;
    Gtk::Main::quit();
}
maybe someone know how to correct it :-/
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP