我是新來這個空地事情(也來這個論壇),並想知道是否有你們的可以幫助我:Glade-GTK + C語言:如何使用FileChooserButton獲取文件名?
我得從chooserbutton用戶選擇的文件名和發送它作爲一個函數的字符串。不幸的是,我一直在收到這個惱人的錯誤:
Gtk-CRITICAL **: IA__gtk_file_chooser_get_uri: assertion `GTK_IS_FILE_CHOOSER (chooser)' failed
我認爲這是由於小部件的錯誤使用。有人能幫我弄清楚嗎?源代碼如下,如您所見,它來自於在https://live.gnome.org/Glade/Tutorials上發現的Glade-GTK教程。
該程序是一個簡單的2按鈕窗口:第一個按鈕是filechooserbutton,第二個是單擊時調用「clica」功能的標準按鈕。它應該顯示用戶通過文件選擇器按鈕選擇的文件名,但這是錯誤發生的時候。
測試源(只是爲了弄清楚如何使用控件):
#include <gtk/gtk.h>
int
main(int argc,
char **argv)
{
GtkBuilder *builder;
GtkWidget *window;
GError *error = NULL;
/* Init GTK+ */
gtk_init(&argc, &argv);
/* Create new GtkBuilder object */
builder = gtk_builder_new();
/* Load UI from file. If error occurs, report it and quit application.
* Replace "tut.glade" with your saved project. */
if(! gtk_builder_add_from_file(builder, "tut.glade", &error))
{
g_warning("%s", error->message);
g_free(error);
return(1);
}
/* Get main window pointer from UI */
window = GTK_WIDGET(gtk_builder_get_object(builder, "window1"));
/* Connect signals */
gtk_builder_connect_signals(builder, NULL);
/* Destroy builder, since we don't need it anymore */
g_object_unref(G_OBJECT(builder));
/* Show window. All other widgets are automatically shown by GtkBuilder */
gtk_widget_show(window);
/* Start main loop */
gtk_main();
return(0);
}
void clica(GtkFileChooser *filechooserbutton1){//this button was inserted through Glade
char cNome[250];
*cNome = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(filechooserbutton1));
printf("\n%s", cNome);
}
格萊德文件:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.24"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<child>
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkFileChooserButton" id="filechooserbutton1">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">button</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="clicked" handler="clica" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>