我一直在搜索我能找到的每个文档源,查看源代码示例,但我仍然不知道如何将GtkEntryCompletion用于我的GtkEntry。
知道如何手动完成,没有林间空地,源代码示例很丰富,但只有在我获得树对象后它们才适用。
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkListStore" id="liststore1"/>
<object class="GtkEntryCompletion" id="entrycompletion1">
<property name="model">liststore1</property>
</object>
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Run Command</property>
<property name="resizable">False</property>
<property name="window_position">center</property>
<property name="type_hint">dialog</property>
<property name="decorated">False</property>
<signal name="destroy" handler="gtk_main_quit" swapped="no"/>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">2</property>
<property name="margin_bottom">2</property>
<property name="label" translatable="yes">Run Command:</property>
<property name="single_line_mode">True</property>
<property name="max_width_chars">70</property>
<property name="track_visited_links">False</property>
<property name="xalign">0.039999999105930328</property>
<property name="yalign">0</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_bottom">5</property>
<property name="width_chars">70</property>
<property name="caps_lock_warning">False</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">False</property>
<property name="secondary_icon_sensitive">False</property>
<property name="completion">entrycompletion1</property>
<signal name="activate" handler="cb_activated" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
#include <stdlib.h>
#include <glib.h>
#include <gtk/gtk.h>
struct widgets {
GtkWidget *window1;
GtkWidget *entry1;
GtkWidget *label1;
};
static void get_widgets(struct widgets *widgets, GtkBuilder *builder) {
widgets->window1 = GTK_WIDGET(gtk_builder_get_object(builder, "window1"));
widgets->entry1 = GTK_WIDGET(gtk_builder_get_object(builder, "entry1"));
widgets->label1 = GTK_WIDGET(gtk_builder_get_object(builder, "label1"));
}
G_MODULE_EXPORT gboolean cb_activated(GtkWidget *entry, gpointer data) {
GError *err = NULL;
const gchar *entry1_text;
entry1_text = gtk_entry_get_text(GTK_ENTRY(entry));
if (g_spawn_command_line_async(entry1_text, &err))
{
gtk_main_quit();
}
else
{
g_printerr("ERROR: %s\n", err->message);
g_error_free(err);
return FALSE;
}
return TRUE;
}
int main(int argc, char **argv) {
GtkBuilder *builder;
GError *err = NULL;
struct widgets *widgets;
gtk_init(&argc, &argv);
builder = gtk_builder_new();
if (!gtk_builder_add_from_file(builder, "main.glade", &err))
{
g_warning("%s", err->message);
exit(EXIT_FAILURE);
}
widgets = g_slice_new(struct widgets);
get_widgets(widgets, builder);
gtk_builder_connect_signals(builder, widgets);
g_object_unref(G_OBJECT(builder));
gtk_widget_show(widgets->window1);
gtk_main();
g_slice_free(struct widgets, widgets);
return EXIT_SUCCESS;
}
我相信我应该得到liststore1,然后我可以填充它,但是我试过的所有方法都是GTK的断言失败。
答案 0 :(得分:0)