【发布时间】:2013-02-22 03:46:19
【问题描述】:
我正在编写一个小的 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);
我真的是 vala 的新手,我没有看到我的错误。
[编辑]
...
<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 生成。
【问题讨论】:
-
请发布您的 ui 文件...我对您尝试连接到 on_url_Changed 的信号特别感兴趣。
-
我刚刚添加了 UI 文件中涉及到的对象的部分。到目前为止,我只是将 porterty 更改为 static。