Pablo Stickar wrote:
> I would like to ask you for help using the Fl_Menu_Bar class.
>
> More specifically, my problem is that the code:
>
> Fl_Menu_Bar* _menuBar = new Fl_Menu_Bar( 0, 0, _mainWindowWidth, 30 );
> _menuBar->add( "&File", 0, 0, 0, FL_SUBMENU );
> _menuBar->add( "File/&Open sequence", FL_CTRL + 'o',
> (Fl_Callback*)openSequence_handler, this, 0 );
> _menuBar->add( "File/&Close sequence", FL_CTRL + 'w',
> (Fl_Callback*)closeSequence_handler, this, 0 );
> _menuBar->add( "File/&Save", FL_CTRL + 's',
> (Fl_Callback*)saveFile_cb, this, 0 );
> _menuBar->add( "File/&Save as", FL_CTRL + FL_SHIFT + 's',
> (Fl_Callback*)saveAsFile_handler, this, 0 );
> _menuBar->add( "File/&Quit", FL_CTRL + 'q',
> (Fl_Callback*)quit_cb, this, 0 );
> _menuBar->add( "&Edit", 0, 0, 0, FL_SUBMENU );
> _menuBar->add( "Edit/&Copy", FL_CTRL + 'c',
> (Fl_Callback*)copySequence_handler, this, 0 );
>
> for( int i = 0; i< _menuBar->size(); ++i )
> { Fl_Menu_Item* m = (Fl_Menu_Item*)&(_menuBar->menu()[i]);
> std::cout<< m->label()<< std::endl;
> }
>
> produces _only_ the output
>
> &File
> &Open sequence
> &Close sequence
> &Save
> &Save as
> &Quit
>
> and nothing else.
I don't see anything obvious that's wrong with your code, but I'm
not a "menubar expert". I added your code to test/menubar.cxx,
changed variable names and callbacks, and it worked well, showing
all previously existing and the added menu labels.
> On top of that, the menu does not work at all. If I comment out the for()
> loop, then the menu works.
>
> Any tip will be very much appreciated. Thanks!
This looks as if your program overwrites some memory in other
functions that are not shown in your code. My tip #1 would
normally be to make a minimal, but complete, compileable example
and try to reproduce your problem. If you can, post it here so
that we can compile and correct it. However, in your case this
will probably not work because the problem is somewhere else.
Tip #2: try running your program with a debugger and/or with
valgrind. This may give you some hints. Please note that in
such cases like yours (commenting out unrelated code changes
the program's behavior) it may be possible that the program
runs w/o *visible* problems when compiled with debugging options.
Note that valgrind is only available for Linux. What OS and
FLTK version do you use, BTW ? (I can see that it's FLTK 1.x,
but which exact version?)
Tip #3: check all your other code, remove parts, look for arrays
that are too small, and so on, until you find the culprit.
Good luck!
Albrecht
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk