1

我想使用该connect_signals方法将我的 Glade 信号绑定到 Gjs/Seed 方法。
但我总是收到以下错误:Argument 'user_data' (type void) may not be null
有谁知道如何使用该connect_signals方法?

Gjs/种子文件

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>
4

1 回答 1

1

由于 user_data,我无法让 connect_signals 工作void*,但 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;
}
于 2013-05-16T13:22:30.587 回答