我是glade的新手(也是这个论坛的新手),我想知道你们中是否有人可以帮助我:
我必须从选择按钮中获得用户选择的文件名,并将其作为字符串发送给函数。不幸的是,我一直收到这个恼人的错误:
Gtk-CRITICAL **: IA__gtk_file_chooser_get_uri:断言' GTK_IS_FILE_CHOOSER (chooser)'失败
我认为这是由于错误的使用小部件。有人能帮我弄明白吗?源代码如下,如您所见,它来自于https://live.gnome.org/Glade/Tutorials上的一个Glade-GTK教程。
程序是一个简单的2按钮窗口:第一个按钮是filechooserbutton,第二个是在点击时调用" click "函数的标准按钮。它应该显示用户通过文件选择器按钮选择的文件名,但这就是错误发生的时候。
测试源代码(只是为了弄清楚如何使用小部件):
#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>
04/01/2013更新(现在我们有glade文件)
我们现在可以看出您使用了错误对象的信号。你把"click "回调连接到GtkButton "button1"的"clicked"信号,而不是把它连接到GtkFileChooserButton "filechooserbutton1"。
原始答:没有格莱德的文件,我们就看不出你连接了哪些信号,也看不出它们连接的是什么。但很有可能你并没有遵循信号的原型。如果断言失败,这意味着在你的回调中,你认为是GtkFileChooser的第一个参数是别的东西