Re: [gtkmm] adding a widget to a container



Ainsley Pereira a e'crit :

Hi again,

I'm not quite sure I follow your description, but there are a couple of
things I can point at for you to investigate further:

On Mon, May 03, 2004 at 06:00:26PM +0200, cedric wrote:
so to do this, i ve 2 ptr declared in my Plugin.hh file
  static Gtk::HBox *toolBarModContainer_ptr;
  static Gtk::Toolbar *toolBarModDisplayed_ptr;

If you declare a static, it's visible only to that translation unit
(think of this as the .cc file and all the files it #includes). Putting
a static in a .h file is almost always the wrong thing to do - if two
.cc files include it, you end up with TWO copies of the variable, both
with the same name, but not the same variable. If you're including
Plugin.hh from two different .cc files, and setting the variable in one,
but using it in the other, you're not setting the same variable.

ah ok! someone (not on this ml) told me to put the "static" in the .hh ...
i have several files which herits from Plugin.hh, this can be the problem!
but it s strange that in some cases it works well (when i just hide the widget pointed by the pointers) and other times not (when i add a toolbar to the container pointed), and this in the same file. Anyway, to have those pointer accessible and unique in all the files which herits from Plugin.hh, what should i do? just put off the "static" keyword? if i do this, i have a compilation error saying that the pointers are not static members of the Plugin class (if i leave a declaration of the pointers like "Plugin::Gtk::HBox *toolBarModContainer_ptr" in the loadplugin.cc file which herits from Plugin.hh), and/or saying the pinters are not declared (if i remove these declarations).

(General hint: Always initialise pointers at declaration. If you can't
give them their final value yet, initialise them to 0. If you do that
here, you can at least verify whether what I've described above is
what's happening in your code, by checking if it's still 0 before you
use it.)
ok, i ll remember to do that in the future!
but i can t initialise it in the .hh files :p


when i put this, it provoques a segfault:

Do you mean a segfault here? or a link error?
it s a seg fault, but there is a link error instead if declare toolbarmod as static.

thanks,

cedric




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