The hack approach: declare cards globally and use it as needed.Fl_Tabs *cards;void but1_Callback(...) {cards = new Fl_Tabs(40,40,300,200);
Tried this one quickly and I get a SIGSEV ("Segmentation fault")
Hard to say without seeing all the code.
This seems to work for me; a modified version of the code
lifeatt...@gmail.com's code.
Try simply copy/pasting this inplace of the code you're using
now, and if it works,
carefully compare it to your old code to see what's wrong.
In this modified version I added 3 tabs to your tab widget
just so it can be seen
when the Open menu item is chosen.
#include <FL/Fl_Window.H> #include <FL/Fl_Radio_Round_Button.H> #include <FL/Fl_Menu_Bar.H> #include <FL/Fl_Tabs.H> Fl_Tabs *cards = 0; void showCards(Fl_Widget *w, void *data) { cards->show(); } Fl_Menu_Item menu_items[] = { // label shortcut callback userdata flags labeltype labelfont labelsize labelcolor // -------------- -------- -------- -------- ---------------- ----------------------- --------- --------- ---------- {"GeneralJournal", 0, 0, 0, FL_SUBMENU, (uchar)FL_NORMAL_LABEL, 0, 10, FL_YELLOW}, {"Open", FL_ALT+'o', showCards, 0, 0, 0, FL_ITALIC, 10, FL_YELLOW}, {"Save", FL_ALT+'s', 0, 0, 0, 0, 0, 10, FL_YELLOW}, {"Cancel", FL_ALT+'a', 0, 0, FL_MENU_DIVIDER, 0, 0, 10, FL_YELLOW}, {"Exit", FL_ALT+'x', 0, 0, 0, 0, 0, 10, FL_YELLOW}, {0}, {0,0,0,0,0,0,0,0,0} }; void but1_Callback(Fl_Widget *w, void *d) { Fl_Window *window2 = new Fl_Window(625, 450); Fl_Menu_Bar *rog = new Fl_Menu_Bar(0, 0, 625, 25); rog->menu(menu_items); cards = new Fl_Tabs(40,40,300,200); // 3 groups makes 3 tabs Fl_Group *tab1 = new Fl_Group(40,40+25,300,200-25,"Tab1"); tab1->end(); Fl_Group *tab2 = new Fl_Group(40,40+25,300,200-25,"Tab2"); tab2->end(); Fl_Group *tab3 = new Fl_Group(40,40+25,300,200-25,"Tab3"); tab3->end(); cards->end(); window2->end(); cards->hide(); window2->show(); } int main(int argc, char **argv) { Fl_Window *window1 = new Fl_Window(200,200,"Roger's Window"); int x = 0; int y = 0; Fl_Radio_Round_Button *but1 = new Fl_Radio_Round_Button(x+15, y+1*20, 70, 15, "SYSTEM"); but1->callback(but1_Callback); window1->end(); window1->show(); return Fl::run(); }
On 9/24/22 16:04, roger tunnicliffe wrote:
Copy and pasted your working version code and it compiled (after adding FL/Fl.H) okay but when I stepped thru the program "cards->show()" did nothing (nothing displayed) ???
On 9/24/22 23:17, roger tunnicliffe wrote:
Thanks guys, I have found the difference but do not understand it..
I had coded:-Fl_Tabs *cards = new Fl_Tabs(40,40,300,200);
while your demonstration has coded:-cards = new Fl_Tabs(40,40,300,200);
Would be very grateful if you could explain the difference
You should probably
start by learning
the C++ language
first
using a tutorial
or book so you can
get down the basics
of the language.
Then segue into
FLTK once you're
comfortable with
C++.
With that said, the C++ programming topics you're
running into here are:
"variable scope" -- once a
variable is declared, how long it remains visible
"variable shadowing" -- how
variables of the same name can 'shadow' each other,
depending on scope
"pointers"
-- accessing objects and memory via indirection
When you added the global variable
'cards', but also declared a local variable 'cards'
and initialized that, the global variable
remains unset, since the local variable shadows it.
This causes the global to remain
uninitialized.
And since the variable is a pointer, the machine
segfaults your app (crashes it) the moment
you try to indirect through the uninitialized
pointer (via cards->xxx), causing a memory
violation.
You can read up on
C++ variable scoping rules here:
https://codescracker.com/cpp/cpp-scope-rules.htm
..and variable shadowing here:
https://www.learncpp.com/cpp-tutorial/variable-shadowing-name-hiding/
But this is kinda sliding off topic
for this forum, as these are questions not so much
about FLTK, and more about the basics of the C++ language
itself. I know it's hard to
know that when you're new to the language, which is why I
think it'll help if you learn
the language first.
On 9/24/22 23:19, roger tunnicliffe wrote:
" That's because no tabs were defined in your Fl_Tabs widget,
making it effectively 'invisible'."
I did actually have them coded but just did not show that in the code I pasted as I had tried to supply only the relevant information. (obviously that was relevant (lol))
Heh -- yes, it's hard to know what's relevant and what isn't
when starting out.
It's best to try to reduce problems to complete but simple
working programs.
There's a simple example of using
tabs on my FLTK cheat page.