Signal ::expose-event 对 GdkWindow 和 GdkX11Window 无效
Signal ::expose-event is invalid for GdkWindow and GdkX11Window
我从其中一个在线教程中提取了以下代码。当我使用 gtk+-2.0 时,下面的代码工作正常。
但是当我尝试用 gtk+-3.0 编译时,代码给出了这个错误:
signal 'expose-event' is invalid for instance of type 'GtkWindow'
所以我尝试执行以下操作,但仍然无济于事。它给出了另一个错误:
signal 'expose-event' is invalid for instance of type 'GdkX11Window'
gtk_widget_realize(window);
GdkWindow *gdkwin = gtk_widget_get_window(Gwindow);
int main(int argc, char *argv[])
{
GtkWidget *window;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(window, "expose-event",
G_CALLBACK (on_expose_event), NULL);
g_signal_connect(window, "destroy",
G_CALLBACK (gtk_main_quit), NULL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 230);
gtk_widget_set_app_paintable(window, TRUE);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
Migrating from gtk2 to gtk3, section Changes that need to be done at the time of the switch
The GtkWidget “expose-event” signal has been replaced by a new “draw” signal, which takes a cairo_t instead of an expose event. The cairo context is being set up so that the origin at (0, 0) coincides with the upper left corner of the widget, and is properly clipped.
无需连接任何信号即可使您的代码正常工作。
我从其中一个在线教程中提取了以下代码。当我使用 gtk+-2.0 时,下面的代码工作正常。
但是当我尝试用 gtk+-3.0 编译时,代码给出了这个错误:
signal 'expose-event' is invalid for instance of type 'GtkWindow'
所以我尝试执行以下操作,但仍然无济于事。它给出了另一个错误:
signal 'expose-event' is invalid for instance of type 'GdkX11Window'
gtk_widget_realize(window);
GdkWindow *gdkwin = gtk_widget_get_window(Gwindow);
int main(int argc, char *argv[])
{
GtkWidget *window;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(window, "expose-event",
G_CALLBACK (on_expose_event), NULL);
g_signal_connect(window, "destroy",
G_CALLBACK (gtk_main_quit), NULL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 230);
gtk_widget_set_app_paintable(window, TRUE);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
Migrating from gtk2 to gtk3, section Changes that need to be done at the time of the switch
The GtkWidget “expose-event” signal has been replaced by a new “draw” signal, which takes a cairo_t instead of an expose event. The cairo context is being set up so that the origin at (0, 0) coincides with the upper left corner of the widget, and is properly clipped.
无需连接任何信号即可使您的代码正常工作。