gpt4 book ai didi

c - Glade-GTK+ C语言: How to use FileChooserButton to get a filename?

转载 作者:太空宇宙 更新时间:2023-11-03 23:53:28 27 4
gpt4 key购买 nike

我是这个林间空地(也是这个论坛)的新手,想知道你们中是否有人可以帮助我:

我必须获取用户从选择器按钮中选择的文件名,并将其作为字符串发送给函数。不幸的是,我一直收到这个恼人的错误:

Gtk-CRITICAL **: IA__gtk_file_chooser_get_uri: assertion `GTK_IS_FILE_CHOOSER (chooser)' failed

我以为是widget的错误使用。有人可以帮我解决这个问题吗?源代码在下面,如您所见,它来自 https://live.gnome.org/Glade/Tutorials 上的 Glade-GTK 教程。 .

该程序是一个简单的 2 按钮窗口:第一个按钮是文件选择器按钮,第二个是标准按钮,单击时调用“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>

最佳答案

04/01/2013 更新(现在我们有了空地文件)

我们现在可以看到您使用了错误对象的信号。您将“clica”回调连接到 GtkButton“button1”的“clicked”信号,而不是将其连接到 GtkFileChooserButton“filechooserbutton1”。

原始答案:没有 glade 文件,我们无法看到您连接了哪些信号,也看不到它们连接的是什么。但很可能您没有遵循信号的原型(prototype)。如果断言失败,这意味着在您的回调中,您认为是 GtkFileChooser 的第一个参数是其他东西。

关于c - Glade-GTK+ C语言: How to use FileChooserButton to get a filename?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14142183/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com