Re: EuGTK - Segmentation fault, GtkCheckMenuItem
- Posted by irv Oct 19, 2010
- 1033 views
Hmm... let me rephrase that so it's clearer:
When you toggle a check button from active to inactive, or vice-versa, it's the same as clicking on it to change the state.
So, if you have connected any signal to that button so that it responds to changes in state, that routine (or any routine it calls) can't also change the state, else your routine will just sit there in a loop.
Here's a simple demo:
include GtkEngine.e function Foo(atom x) ? x set(x,"active",0) set(x,"active",1) return 1 end function load_xml(builder,"cktest1.glade") connect("window1","destroy",quit) connect("checkbutton1","clicked",call_back(routine_id("Foo"))) show_all("window1") main()
The above code will loop until you get a seg fault. Note that it isn't necessary to directly call the offending routine from the connect signal. You may be connecting to some other function that calls the endless loop proc().
BTW, it's normally not a good idea to connect any action to clicking on a check button/box. Suppose the page has 2 or more check items. Do you really want to go do something each time one is clicked, or do you want to wait until the user has finished and has them all set the way he wants? IOW, set up the check buttons/boxes, etc, and then put an OK button to be clicked when the selections are finished.
If you feel you MUST do something the moment a checkbox is clicked, then use the "pressed" or "released" signal rather than the "clicked" signal. This way, you won't get into an endless loop, 'cause your response will be to a mouse action rather than a state change. This works well for a checkmenu item.
However, looking at your code, I wonder if you are trying to use checkmenuitems as radiomenuitems - turning off all the others when one is clicked?