By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,906 Members | 1,384 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,906 IT Pros & Developers. It's quick & easy.

An off-topic question

P: n/a
I know that this is not a C++ question, but in the hope that some other
programmer with GTKmm programming experience would come to this
newsgroup, read my message and give me a hand on this issue I am
posting the question here.I know that there is a mailing list for
GTKmm, however, the list is very slow; to a point where one feel lucky
to get a reply, what a shame.
I am trying to write a class that derives from Gtk::VBox called
Contacts; the idea is to pack every widget necessary to display and
retrieve data from the user using a one class. This class will be
passed to a Gtk::Notebook::append_page().
The class compiles just fine, but at the point where I add the
Gtk::HBox object to the Gtk::VBox derived class the program
craches/segmentation fault.

Could someone please tell me what I am doing wrong?

Here is the example:
==========
WinXP
MinGW-GCC

class Contacts : virtual public Gtk::VBox{
protected:
Gtk::HBox hbox1;
Gtk::HBox hbox2;

public:
Contacts();
virtual ~Contacts();
}; //class
jme::Contacts::Contacts(){
this->pack_start(hbox1); //Segmentation Fault
}
==============

TIA

Nov 8 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
>this->pack_start(hbox1); //Segmentation Fault

aren't you calling pack_start on this object before "this" is
completely constructed?

G

Nov 8 '05 #2

P: n/a
Gr*****@nospam.com wrote:
this->pack_start(hbox1); //Segmentation Fault


aren't you calling pack_start on this object before "this" is
completely constructed?


Yes and no. The OP's code was:

class Contacts : virtual public Gtk::VBox{
protected:
Gtk::HBox hbox1;
Gtk::HBox hbox2;

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

jme::Contacts::Contacts(){
this->pack_start(hbox1); //Segmentation Fault
}

At the point of the segfault, all of the bases and members of Contacts
are constructed and [this] points to the current object, so there
should be no problem using data members (e.g., hbox1) or a member
function or base-class' function (e.g. pack_start). The exception is if
pack_start() is a virtual function that is actually over-ridden by
Contacts (which is not shown in the OP). See this FAQ:
http://www.parashift.com/c++-faq-lit....html#faq-23.5
..

Also, the use of [this] seems to be unnecessary in the constructor
unless there's some funny business going on that is not evident from
the OP. The body would likely be the same if it read:

pack_start( hbox1 );

Cheers! --M

Nov 8 '05 #3

P: n/a
Al-Burak wrote:
I know that this is not a C++ question, but in the hope that some other
programmer with GTKmm programming experience would come to this
newsgroup, read my message and give me a hand on this issue I am
posting the question here. I know that there is a mailing list for
GTKmm, however, the list is very slow; to a point where one feel lucky
to get a reply, what a shame.
Only this time. We'll check you from now on.
I am trying to write a class that derives from Gtk::VBox called
Contacts; the idea is to pack every widget necessary to display and
retrieve data from the user using a one class. This class will be
passed to a Gtk::Notebook::append_page().
The class compiles just fine, but at the point where I add the
Gtk::HBox object to the Gtk::VBox derived class the program
craches/segmentation fault.

Could someone please tell me what I am doing wrong?

Here is the example:
==========
WinXP
MinGW-GCC

class Contacts : virtual public Gtk::VBox{
protected:
Gtk::HBox hbox1;
Gtk::HBox hbox2;

public:
Contacts();
virtual ~Contacts();
}; //class
jme::Contacts::Contacts(){
this->pack_start(hbox1); //Segmentation Fault
}
==============


This could be anything. Make sure (I don't know gtk) you are using the
library correctly, check the arguments you are passing, check your
inheritance, etc. Perhaps something is going wrong in the HBox
constructors, or in the base class.

If this appears to be correct, make sure memory allocations are done
correctly. How do you create Contacts objects? On the heap? If so, are
they correctly created/used/deleted?

I hope it's a stupid error with the library. If not, you'll probably
need a couple of days to solve the problem because this looks like
undefined behavior.

Good luck!
Jonathan

Nov 8 '05 #4

P: n/a
[snip[
The class compiles just fine, but at the point where I add the
Gtk::HBox object to the Gtk::VBox derived class the program
craches/segmentation fault.

[snip]

A debugger can give you more information about a crash, such as a
backtrace. valgrind's memcheck is also very useful.

Murray

Nov 10 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.