0
忍受我,因爲我對GTK和GDK非常陌生。關閉GTK窗口
我想通過幾個圖像循環,對它們進行修改(在各個點繪製一個圓圈),並從標準輸入接受用戶輸入。
我寫了C++類來包裝GTK框架,所以我可以簡化圖像處理。我目前正在打開每個圖像的個別窗口,要求輸入,關閉該窗口,然後打開下一個窗口。
我可以做的一切都很好,除非讓窗口關閉以編程方式,並讓用戶這樣做是不可接受的(即太乏味)。以下是打開和關閉窗口的代碼。
void PixelImage::show() {
gtk_widget_show_all(this->window);
gtk_main();
}
void PixelImage::close() {
gtk_window_close((GtkWindow*)this->window);
}
PixelImage::PixelImage(const char *fname) {
this->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(this->window, "destroy",
G_CALLBACK (gtk_main_quit), NULL);
this->fname = std::string(fname);
this->image = gtk_image_new_from_file(fname);
this->pix = gtk_image_get_pixbuf((GtkImage*)this->image);
this->pixels = gdk_pixbuf_get_pixels(this->pix);
this->len = gdk_pixbuf_get_byte_length(this->pix);
this->width = gdk_pixbuf_get_width(this->pix);
this->height = gdk_pixbuf_get_height(this->pix);
this->nchannels = gdk_pixbuf_get_n_channels(this->pix);
this->rowstride = gdk_pixbuf_get_rowstride(this->pix);
gtk_container_add(GTK_CONTAINER (this->window), this->image);
}
當顯示後調用close時,窗口將保留,當我關閉它時會出現以下錯誤。
(IMG:2173):GTK的CRITICAL **:gtk_widget_get_realized:斷言 'GTK_IS_WIDGET(插件)' 失敗