|
问题:file chooser dialog 获取的文件名在控制台中能正常显示,但不能在文本框entry构件中设置和显示。因为file chooser dialog要重新建立窗口,file chooser dialog的事件信号似乎不能用 lookup_widget 对原窗口的entry构件操作。提示如下:
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
请教:有什么方法能在原窗口window1的entry1构件中显示file chooser dialog的文件名。或请推荐一个类似的C语言应用程式的源码。谢谢!
以下为简化说明:
新建窗口
window1
包含构件
button1(浏览)/*用于获取文件名*/
entry1 /*用于显示获取的文件名*/
建立一个文件选择对话框
filechooserdialog1
包含:cancel (button2)和 open(button3) 两个事件信号
callbacks.h 和callbacks.c如下:
callbacks.h
[code:1]#include <gnome.h>
gchar *filename; /*用于存放获取文件名*/
GtkWidget *window1;/*这里没有再定义一个新窗口window2,测试表明和定义新窗口效果一样,用于装载file chooser dialog构件*/
/*以下为自动生成*/
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);[/code:1]
callbacks.c :
[code:1]void
on_button1_clicked (GtkButton *button,
gpointer user_data)
{
/*在定义的window1上(这和主窗口window1不是同一个)建立并显示file chooser dialog*/
window1 = create_filechooserdialog1 ();
gtk_widget_show (window1);
}
void
on_button2_clicked (GtkButton *button,
gpointer user_data)
{
gtk_widget_destroy (window1);/*销毁在callbacks.h中定义的window1窗口*/
}
void
on_button3_clicked (GtkButton *button,
gpointer user_data)
{
/*获取file chooser dialog选取的文件名*/
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER
(window1));
/*在控制台显示文件名*/
g_print ("your get filename is %s\n",filename);
/*试图在主窗口中的entry1文本框显示获取文件名,但进程却在file chooser dialog窗口filechooserdialog1中找entry1,问题就出在这儿*/
GtkWidget *entry1 = lookup_widget (GTK_WIDGET(button), "entry1");
gtk_entry_set_text (GTK_ENTRY (entry1), filename);
gtk_widget_destroy (window1);
}[/code:1] |
|