Re: Gtk-WARNING **: Can't set a parent on widget which has a parent - Code included - Seeking advise/hints on how to correct my code (SOLVED!)
- From: Jason Alan Smith <jsmith435 cox net>
- To: gtkmm-list gnome org
- Subject: Re: Gtk-WARNING **: Can't set a parent on widget which has a parent - Code included - Seeking advise/hints on how to correct my code (SOLVED!)
- Date: Sun, 19 Jun 2005 17:45:34 -0500
Whoo YaW! OK, took me all darn day, but it's solved. I spent the
better part of the day trying to use a vector to hold the tabs since I
figured out the append_page took a reference so I figured that my tab
was going out of scope so I needed to keep them around, hence the vector
attempt. Problem is, I had to figure out copy constructors and operator
overloading... got it all to compile but it would segfault in the copy
constructor or the = operator overload statement, and I just could not
figure it out.
I went back and tried again to just declare dynamically the new tab
statement. Problem with that is I got a no matching constructor found
for the append_page method of the notebook widget. THEN, it hit me I
could try to dereference the dynamic allocated pointer and bingo baby it
worked. Program compiled and ran I got all the tabs and each text view
holds it's own text...
Anyway, it's fixed so no need to look at this if you have not started
already.
Thanks again!
Jason
On Sun, 2005-06-19 at 13:09 -0500, Jason Alan Smith wrote:
> Good afternoon!
>
> I'm working on my project today and have run into a problem I've been
> banging my head against for a while, trying different things without any
> luck. I'm hoping there are some kind folks here who can offer some
> suggestions as to what I could try.
>
> Basically what I have is a scenario like this:
>
> *** CODE ***
> class mdw : public Gtk::VPaned
> {
> public:
>
> mdw() { pack1(w1, TRUE, TRUE); pack2(w2, TRUE, TRUE); }
>
> private:
>
> protected:
>
> My_Derived_TreeView w2;
> My_Derived_TextView w1;
>
> };
>
> class My_Derived_TreeView : public Gtk::TreeView
> {
> //For now I have no real code in this one
> }
>
> class My_Derived_TextView : public Gtk::TextView
> {
> //For now I have no real code in this one
> }
>
> Now in the code below is I think the start of the problem:
>
> class my_nb : public Gtk::Notebook
> {
> public:
> mdw new_tab; //tried putting this in private & protected also
> ***ALSO, tried moving this into the Add function, and this eliminates
> the errors below, but I think the widget is going out of scope once Add
> ends and that is why (I think) that no tab shows up in the notebook when
> I do it this way... so I kind of know what the problem is, but not sure
> how to fix it***
>
> void Add(std::string Name) { append_page(new_tab, Name); }
> }
>
> Now, in my main window:
>
> In the header file inside the class def. for the main window I have:
>
> protected:
> my_nb m;
>
> In the cxx (implementation) file for the main window I have:
>
> Inside the constructor:
>
> m.Add("Tab1");
> m.Add("Tab2");
> ...
> m.Add("Tab5");
>
> *** END CODE ***
>
> Ok, that's the code in a nutshell.
>
> When I compile this I get no messages. I use this to compile it:
>
> g++ -Wall Edm_Main_Window.cxx main.cc -o simple `pkg-config gtkmm-2.4
> --cflags --libs`
>
> These are the messages I get when I run the app:
>
> (simple:24463): Gtk-WARNING **: Can't set a parent on widget which has a
> parent
> (simple:24463): Gtk-WARNING **: Can't set a parent on widget which has a
> parent
> (simple:24463): Gtk-WARNING **: Can't set a parent on widget which has a
> parent
> (simple:24463): Gtk-WARNING **: Can't set a parent on widget which has a
> parent
>
> This is what I see in the main window:
>
> I see all five notebook tabs. But let's say tab1 is displayed and I
> type something into the textview in tab1 then change to tab2 and the
> textview still shows what I typed in tab1. I know from previous
> experience that this indicates the textview and probably the treeview
> did not get parented right, and the messages above hint at that as well.
>
> I've tried using references (something I have little knowledge of right
> now) as well as pointers and the new operator but did not have success.
> I've also tried changing the Gtk::VPaned to just a Gtk::Frame and even
> with adding no widgets to the frame but still get those messages above.
> And I'm very aware this may just be my lack of a good understanding of c
> ++. I've tried moving
>
> I would very much appreciate any hints you may be able to offer.
>
> Thank you most sincerely,
>
> Jason
>
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list
--
Jason A. Smith
jasmithoffice yahoo com
Read My Blog at www.livejournal.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]