Gtk3 vala中对象实例和信号处理程序的分段错误

Gtk3 vala中对象实例和信号处理程序的分段错误,gtk3,vala,Gtk3,Vala,我正在编写一个小http客户端来测试api调用。这是学习vala和使用gtk3的机会 我制作了一个类来处理gtk接口和http请求 using GLib; using Gtk; public class RequestHandler : Object { public string uri { get; private set; default = ""; } // Constructor public RequestHandler () { }

我正在编写一个小http客户端来测试api调用。这是学习vala和使用gtk3的机会

我制作了一个类来处理gtk接口和http请求

using GLib;
using Gtk;

public class RequestHandler : Object
{
    public string uri { get; private set; default = ""; }

    // Constructor
    public RequestHandler ()
    {
    }

    [CCode (instance_pos = -1)]
    public void on_url_changed (Entry entry, Button button)
    {
        stderr.printf ("this#%p\n", this);
        if (entry.get_text_length () == 0)
        {
            button.set_sensitive (false);
            this.uri = "";
        }
        else
        {
            button.set_sensitive (true);
            this.uri = entry.get_text();
        }
    }

    [CCode (instance_pos = -1)]
    public void on_send_clicked (Button button)
    {
        assert (this.uri != null );
        stderr.printf ("Send request to : %s\n", this.uri);
    }
}
线路

stderr.printf ("this#%p\n", this);
// => fprintf (_tmp0_, "this#%p\n", self); in the C file
每次“this#0x1”和程序因线路分段故障而失败时显示

this.uri = entry.get_text();
// _g_free0 (self->priv->_uri); in the C file
用户界面是用

var builder = new Builder ();
builder.add_from_file (UI_FILE);
var signals_handler = new RequestHandler ();
builder.connect_signals (signals_handler);
我真的是瓦拉的新手,我看不出我的错误

[编辑]

...
<object class="GtkEntry" id="entry2">
    <property name="visible">True</property>
    <property name="can_focus">True</property>
    <property name="receives_default">True</property>
    <property name="hexpand">True</property>
    <property name="invisible_char">●</property>
    <property name="input_purpose">url</property>
    <signal name="changed" handler="request_handler_on_url_changed" object="button1" swapped="no"/>
</object>
...
。。。
真的
真的
真的
真的
●
网址
...

用户界面完全由glade生成。

您有一个关于on_url_changed方法的额外参数。信号应该有一个参数:Gtk.Editable,它已更改。由于没有自动连接信号的类型安全性,
public void on_已更改(Gtk.Entry)应该可以工作

您在上面发布的代码所发生的情况是,生成了如下内容:

void request_handler_on_changed (GtkEntry* entry, GtkButton* button, RequestHandler* self) {
  fprintf (stderr, "this#%p\n", self);
}
gtk+称之为

request_handler_on_changed (editable, request_handler);
因此,当您的Vala代码获取信息时,它在按钮参数中包含RequestHandler,而self(即“this”变量的生成方式)是垃圾


在自动连接信号时,您必须非常小心,因为您基本上绕过了Vala并直接连接到生成的C。Vala无法提供类型安全性。

请发布您的ui文件。。。我特别感兴趣的是,您试图连接的信号在url上发生了变化。我刚刚添加了UI文件中有关所涉及对象的部分。到现在为止,我只是把porterty改为static。Thx,现在可以工作了。所以,我不能将“自动连接信号”与实例方法和额外的图形结合使用。糟透了。