|
自己作的一个词典程序, 在命令行正常执行. 用 Glade 作了个界面 . 执行时却只能
显示单词, 词性, 音标等英文信息. 而不能显示词典库里的中文解释.
[code:1]
[sihan@localhost src]$ ./test01
(test01:18132): Gtk-CRITICAL **: file gtktextbuffer.c: line 543 (gtk_text_buffer_emit_insert): assertion `g_utf8_validate (text, len, NULL)' failed
[/code:1]
用 Gdb 调试:
[code:1]
(gdb) b callbacks.c :72
Breakpoint 1 at 0x804a6ce: file callbacks.c, line 72.
(gdb) r
Starting program: /home/sihan/program/gtk/test04/src/test01
Breakpoint 1, on_button_search_clicked (button=0xbffd53a0, user_data=0x0)
at callbacks.c:72
72 print_word(words, textview1);
(gdb) p words.node->exp
$1 = 0x92c85d8 "离去, 走, 进行, 变成, 趋于, 达到, 求助于, 诉诸"
(gdb)
[/code:1]
说明已经找到了. 下面是textview1 中显示的信息:
[code:1]
go
-------------------------
^Eu
vi.
------>这里没有解释项
[/code:1]
这是部分代码:
[code:1]
void
on_button_search_clicked (GtkButton *button,
gpointer user_data)
{
GtkWidget *textview1 = lookup_widget (GTK_WIDGET(button), "textview1");
GtkWidget *entry1 = lookup_widget (GTK_WIDGET(button), "entry1");
GtkTextBuffer *buffer;
GtkTextIter iter;
gchar *word;
WORD words;
init_node(&(words.node));
word = gtk_entry_get_text(GTK_ENTRY(entry1));
//*********************************************************
char confit_file_name[] = "/home/sihan/bin/confit.txt";
char path[80];
char num = 'A';
FILE *fp;
int i;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(textview1));
gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
if( read_file(confit_file_name, path, DICT_DIR_EC, num) ==0)
{
printf("please confit confit file !\n");
exit(1);
}
i = strchr(path, '.') - path -1;
path[i] = tolower(word[0]);
if((fp=fopen(path, "r")) ==NULL)
{
printf("\nDic file open error !\n\n");
exit(1);
}
while(!feof(fp))
{
if(myread(&words, fp, word) == 0)
break;
if( strcmp(words.word, word) == 0)
break;
else
{
free(words.word);
words.word = NULL;
}
}
fclose(fp);
if(words.word == NULL)
{
gtk_text_buffer_insert( buffer, &iter, "Word Unfinded\n", -1);
}
else
{
print_word(words, textview1);
free_word(&words);
}
free(word);
word = NULL;
}
void print_word(WORD words, gpointer *textview1)
{
WNODE *p;
GtkTextBuffer *buffer;
GtkTextIter iter;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(textview1));
gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
gtk_text_buffer_insert( buffer, &iter, "\n", -1);
gtk_text_buffer_insert( buffer, &iter, words.word, -1);
gtk_text_buffer_insert( buffer, &iter, "\n", -1);
gtk_text_buffer_insert( buffer, &iter, "-------------------------\n", -1);
gtk_text_buffer_insert( buffer, &iter, words.node->ps, -1);
gtk_text_buffer_insert( buffer, &iter, "\n", -1);
gtk_text_buffer_insert( buffer, &iter, words.node->pos, -1);
gtk_text_buffer_insert( buffer, &iter, "\n", -1);
gtk_text_buffer_insert( buffer, &iter, "", -1);
gtk_text_buffer_insert( buffer, &iter, words.node->exp, -1);
gtk_text_buffer_insert( buffer, &iter, "\n", -1);
}
[/code:1]
我觉得可能是汉子字符的问题, 但是不知到怎么转换 g_convert() 这个函数怎么用?
还有一个问题:
[code:1]
怎么在textview里改变文字的字体, 因为音标那一项要用金山的音标字体.
[/code:1] |
|