Problem with Fl_Pack

8 views
Skip to first unread message

david allen

unread,
Jan 4, 2022, 3:56:11 PM1/4/22
to fltk.general
All children take the label of the last child. I've tried a few things like using "add" and specifying labels apart from the constructors to no avail.
pack.cpp

Ian MacArthur

unread,
Jan 4, 2022, 4:37:27 PM1/4/22
to Fltk General
On 4 Jan 2022, at 20:56, david allen wrote:
>
> All children take the label of the last child. I've tried a few things like using "add" and specifying labels apart from the constructors to no avail.


David,

You’ve used the same char array “label” for all the labels, so that’s why they are the same...

If you are doing that, you need to use the copy_label() method rather than just the label() method.

Check the docs, but basically label() just retains a pointer to the array you use, so if it then changes or goes out of scope, bad things can happen. If you use copy_label() the widget will make a local copy and then it doesn’t matter what happens to the “label” array - but costs you more memory...

This is true of all fltk labels, I think, and is not peculiar to the Fl_Pack class.

david allen

unread,
Jan 4, 2022, 5:00:46 PM1/4/22
to fltk.general
Thanks!
Reply all
Reply to author
Forward
0 new messages