An off-topic question

A

Al-Burak

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
 
G

Grahamo

this->pack_start(hbox1); //Segmentation Fault

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

G
 
M

mlimber

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-lite/strange-inheritance.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
 
J

Jonathan Mcdougall

Al-Burak said:
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
 
M

murrayc

[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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top