我想使用connect_signals
方法将我的Glade信号绑定到Gjs / Seed方法
但我总是得到以下错误:Argument 'user_data' (type void) may not be null
有谁知道如何使用connect_signals
方法?
Gtk.init(null, 0);
let builder = new Gtk.Builder();
builder.add_from_file( "ui.glade" );
builder.connect_signals(this);
Gtk.main();
function on_button_ok_clicked() {
print("ok");
};
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkWindow" id="window">
<child>
<object class="GtkButton" id="button_ok">
<signal name="clicked" handler="on_button_ok_clicked" swapped="no"/>
</object>
</child>
答案 0 :(得分:1)
由于void*
user_data,我无法使connect_signals正常工作,但connect_signals_full确实有一些神秘的原因: - )
const SignalHandlers = new Lang.Class({
Name: 'SignalHandlers',
_init: function () {},
your_switch_active_notify_cb: function (object) {
print("switch is active:" + object.get_active());
},
_connector: function(builder, object, signal, handler) {
object.connect(signal, Lang.bind(this, this[handler]));
},
});
function buildPrefsWidget() {
let win = new Gtk.Table(), ui = new Gtk.Builder();
ui.add_from_file(Me.dir.get_path() + "/prefs.ui");
ui.get_object("content-table").reparent(win);
let signal_handlers = new SignalHandlers();
ui.connect_signals_full(Lang.bind(signal_handlers, signal_handlers._connector));
return win;
}