GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Oct 31, 2014 7:20 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Gtk::Wdiget and Gtk::Notebook, help!
PostPosted: Mon Nov 07, 2005 10:52 pm 
Offline
Familiar Face

Joined: Thu Sep 22, 2005 12:23 pm
Posts: 20
I have a skeleton class that will eventually contains all the elementes needed to display and retrieve information from the users.
The class compiles nicely, but when I add it to the Gtk::Notebook the program issues a segmentation fault:

Here is an snip of the program in question.

OS: WinXP
compiler: MinGW-CPP 3.4.2

namespace jme{
class Contacts : virtual public Gtk::Window{
protected:
Gtk::VBox* vbox1;
Gdk::Color* colour;

public:
Contacts();
virtual ~Contacts();
}; //class
} //namespace

jme::Contacts::Contacts(){
colour = new Gdk::Color();
vbox1 = new Gtk::VBox();

this->vbox1->set_homogeneous(true);
colour->set_rgb(0,255,255);

this->vbox1->modify_bg(Gtk::STATE_NORMAL, *colour);
this->add(*vbox1);

}
jme::Contacts::~Contacts(){
delete colour;
delete vbox1;
}

-----------------------------
namespace jme{
class Jaime : public Gtk::Window
{
public:
Jaime();
virtual ~Jaime();

protected:
....
//Child widgets:
Gtk::Notebook* notebook;
jme::Contacts* contacts;
...
private:
...
//Constructors and Destructor go here
...

};//class
} //namespace

jme::Jaime::Jaime(){
........
contacts = new jme::Contacts();
notebook = new Gtk::Notebook();
notebook->append_page(*contacts, "Contacts");
........
}
jme::Jaime::~Jaime(){
delete all pointers...
}

TIA

_________________
* You cannot exercise your power to a point of humiliation.
- Jean Chretien

* It's amazing how the small seeds of distrust and misunderstanding
can yield a crop of hate and death...

Ma'assalama! Adiós! bye!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 11:32 am 
When inherited classes are constructed first is called the constructor of the base class and then the
constructor of the derived class.

When a derived class is deleted (destroyed) firs is called the derived class destructor and secobd the
base class destructor.

So when the dectructor of the Contacts class is called the vbox1 pointer is deleted, but the Widget
class still has reference to the memory where the vbox1 was pointed.

to avoid the segmentation first you should remove() the vbox1 from the Widget class


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group