Gtk-WARNING **: Can't set a parent on widget which has a parent - Code included - Seeking advise/hints on how to correct my code



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




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]