FLTK logo

Re: [fltk.general] Re: HOWTO = ???->show() in a callback function

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: Re: HOWTO = ???->show() in a callback function Greg Ercolano Sep 24, 2022  
 


On 9/24/22 15:47, roger tunnicliffe wrote:
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 lifeattickville@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();
}


--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/69ba4690-c99c-dca8-20bb-911364b22a18%40seriss.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.