your get filename is :/etc/dhcpd.conf
** (dhcpsetup:29427): WARNING **: Widget not found: entry1
(dhcpsetup:29427): Gtk-CRITICAL **: file gtkentry.c: line 3716 (gtk_entry_set_text): assertion `GTK_IS_ENTRY (entry)' failed
由于才做linux下编程,请教:有什么方法能在原窗口中记录file chooser dialog的文件名。或请推荐一个类似的C语言应用程式的源码。谢谢!
以下为简化说明:
新建窗口
window1
包含构件
button1(浏览)/*用于获取文件名*/
entry1 /*用于显示获取的文件名*/
建立一个文件选择对话框
filechooserdialog1
包含:cancel (button2)和 open(button3) 两个事件信号
callbacks.h 和callbacks.c如下:
callbacks.h
- 代碼: 選擇全部
#include <gnome.h>
gchar *filename; /*用于存放获取文件名*/
GtkWidget *window1;/*这里没有再定义一个新窗口,测试表明和定义新窗口效果一样*/
/*以下为自动生成*/
void
on_button1_clicked (GtkButton *button,
gpointer user_data);
void
on_button2_clicked (GtkButton *button,
gpointer user_data);
void
on_button3_clicked (GtkButton *button,
gpointer user_data);
callbacks.c :
- 代碼: 選擇全部
void
on_button1_clicked (GtkButton *button,
gpointer user_data)
{
window1 = create_filechooserdialog1 ();
gtk_widget_show (window1);
}
void
on_button2_clicked (GtkButton *button,
gpointer user_data)
{
gtk_widget_destroy (window1);
}
void
on_button3_clicked (GtkButton *button,
gpointer user_data)
{
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER
(window1));
g_print ("your get filename is %s\n",filename);
GtkWidget *entry1 = lookup_widget (GTK_WIDGET(button), "entry1");
gtk_entry_set_text (GTK_ENTRY (entry1), filename);
gtk_widget_destroy (window1);
}