4

我已经使用 glade 和 gtk 编写了一个软件 gui。主窗口有一个关于按钮。当我第一次单击该按钮时,GtkAboutDialogBox运行良好。操作区域正确绑定到事件。但是当我关闭它并再次尝试打开关于对话框(没有从主窗口退出)时,什么也没有出现。另外系统会抛出

(tut:5424): GLib-GObject-WARNING **: invalid unclassed pointer in cast to `GtkDialog'
(tut:5424): Gtk-CRITICAL **: IA__gtk_dialog_run: assertion `GTK_IS_DIALOG (dialog)' failed
(tut:5424): GLib-GObject-WARNING **: invalid unclassed pointer in cast to `GtkWidget'
(tut:5424): Gtk-CRITICAL **: IA__gtk_widget_destroy: assertion `GTK_IS_WIDGET (widget)' failed

到壳。这段代码可能有什么问题?

//tut.c
//gcc -o tut tut.c $(pkg-config --cflags --libs gtk+-2.0 gmodule-2.0)
#include <gtk/gtk.h>

GtkBuilder *builder;
GtkWidget  *window,*window_cnb;
GtkAboutDialog *abtwindow;
GtkLabel *label;
GError     *error = NULL;

void on_about_clicked() {
    gtk_dialog_run( GTK_DIALOG(abtwindow) );
    gtk_widget_destroy( GTK_WIDGET(abtwindow) );
}

int main( int    argc,char **argv )  { 
    gtk_init( &argc, &argv );
    builder = gtk_builder_new();
    if( ! gtk_builder_add_from_file( builder, "my.glade", &error ) )  {
        g_warning( "%s", error->message );
        g_free( error );
        return( 1 );
    }
    window = GTK_WIDGET( gtk_builder_get_object( builder, "window1" ) );
    abtwindow = GTK_ABOUT_DIALOG( gtk_builder_get_object( builder, "aboutdialog1" ) );
    label = GTK_LABEL( gtk_builder_get_object( builder, "label16" ) );

    gtk_builder_connect_signals( builder, NULL );
    g_object_unref( G_OBJECT( builder ) );
    gtk_widget_show( window );
    gtk_main(); 
    return( 0 );
}

我使用gtkbuilder。我该如何解决?

4

1 回答 1

3

使用 gtk_widget_hide() 代替 gtk_widget_destroy()。

于 2010-12-01T12:48:03.677 回答