Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > An off-topic question

Reply
Thread Tools

An off-topic question

 
 
Al-Burak
Guest
Posts: n/a
 
      11-08-2005
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

 
Reply With Quote
 
 
 
 
Grahamo@nospam.com
Guest
Posts: n/a
 
      11-08-2005
>this->pack_start(hbox1); //Segmentation Fault

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

G

 
Reply With Quote
 
 
 
 
mlimber
Guest
Posts: n/a
 
      11-08-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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

 
Reply With Quote
 
Jonathan Mcdougall
Guest
Posts: n/a
 
      11-08-2005
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

 
Reply With Quote
 
murrayc@murrayc.com
Guest
Posts: n/a
 
      11-10-2005
[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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question row filter (more of sql query question) =?Utf-8?B?YW5kcmV3MDA3?= ASP .Net 2 10-06-2005 01:07 PM
Quick Question - Newby Question =?Utf-8?B?UnlhbiBTbWl0aA==?= ASP .Net 4 02-16-2005 11:59 AM
Question on Transcender Question :-) eddiec MCSE 6 05-20-2004 06:59 AM
Question re: features of the 831 router (also a 924 question) Wayne Cisco 0 03-02-2004 07:57 PM
Syntax Question - Novice Question sean ASP .Net 1 10-20-2003 12:18 PM



Advertisments