嗨,我是綁寫一個簡單的文本編輯器,我用這個回調來處理主窗口中刪除事件GTK + 2:我的應用程序崩潰上退出
g_signal_connect(G_OBJECT(mainWindow),"delete-event",G_CALLBACK(quit), (gpointer)textView);
,這是我的回調函數來處理此事件
void quit(GtkWidget *wid,GdkEvent *e,gpointer data)
{
GtkTextIter iStart,iEnd;
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textView));
gtk_text_buffer_get_bounds(buffer,&iStart,&iEnd);
gchar * text = gtk_text_buffer_get_text(buffer,&iStart,&iEnd,FALSE);
if(docFile.isSaved == FALSE && strcmp("",text))
{
GtkWidget * msgDialog;
msgDialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_MODAL,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_YES_NO,
"Do you manna save your file ?",
NULL);
switch (gtk_dialog_run (GTK_DIALOG(msgDialog)))
{
case GTK_RESPONSE_YES:
if(docFile.name == NULL)
{
if(saveAs(textView))
{
gtk_widget_destroy (msgDialog);
gtk_main_quit();
}
}
else
{
save(textView);
gtk_widget_destroy (msgDialog);
gtk_main_quit();
}
break;
case GTK_RESPONSE_NO:
gtk_widget_destroy (msgDialog);
gtk_main_quit();
}
}else{
gtk_main_quit();
}
}
,但是當我在我的終端退出我發現這個窗口
(Black Hole) adil Tux : SimpleEditor
>>>> ./a.out
*** Error in `./a.out': free(): invalid pointer: 0x0000000000604570 ***
======= Backtrace: =========
/usr/lib/libc.so.6(+0x7340e)[0x7fefc476a40e]
/usr/lib/libc.so.6(+0x7884e)[0x7fefc476f84e]
/usr/lib/libc.so.6(+0x7900b)[0x7fefc477000b]
./a.out[0x402ad0]
/usr/lib/libc.so.6(__libc_start_main+0xf0)[0x7fefc4717040]
./a.out[0x402069]
======= Memory map: ========
00400000-00404000 r-xp 00000000 08:06 2107681 /home/adil/Src/SimpleEditor/a.out
00604000-00605000 rw-p 00004000 08:06 2107681 /home/adil/Src/SimpleEditor/a.out
01a38000-01b83000 rw-p 00000000 00:00 0
[heap]
....
7fefc736b000-7fefc736c000 rw-p 00022000 08:06 920725 /usr/lib/ld-2.20.so
7fefc736c000-7fefc736d000 rw-p 00000000 00:00 0
7fff6fd1c000-7fff6fd3d000 rw-p 00000000 00:00 0 [stack]
7fff6fdfc000-7fff6fdfe000 r-xp 00000000 00:00 0 [vdso]
7fff6fdfe000-7fff6fe00000 r--p 00000000 00:00 0 [vvar]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
Aborted (core dumped)
,並認爲你。
構建會顯示文件名,函數名以及的代碼中的崩潰發生的地點的行號。您可以通過將'-g'標誌添加到gcc來添加調試信息。 – 2014-10-06 12:23:41
如果您有更新的信息,請更新您的問題,而不是嘗試將大量文本塞進評論中。 – 2014-10-06 12:58:40