Note: I’m not an expert on Vala, GTK+, or anything else for that matter. If I am off base someplace, comment.
I spent quite a some time today trying to get GTKBuilder to automagically connect all my signals to their handlers. I tripped up at a few places, and so recording them here for posterity.
If you are using instance methods (like most of us are), you’ve to decorate your handler function with the attribute
[CCode (instance_pos=-1)]. This makes sure that the function is passed the
thispointer as last argument, rather than first. You’ve to do this because
Builder.connect_signalspasses the instance as last parameter (
user_data), and by aligning your
user_data, you make sure the correct instance is called.
Make sure your handler function signature matches what is expected. Ignore the
user_dataparameter of most signals – it is used internally by
Builder.connect_signals(see above point).
Make sure you pass
--pkg gmodule-2.0to your
valac. If you’re using Autotools, this means you pass it to
sure your C compiler is called with
-dynamic-export. I’m told this enabled support for
dlopenin the binary produced.
Mangle your names properly.
cheese_main_window_on_quiton C, and that is what GTKBuilder expects. If you are not sure how your function name is mangled by
valac, checkout the generated
If you do all these 5 things right and you’re still having trouble, turn up on #vala at irc.gimp.net and ask the helpful folks there :)