Gtk :: Window *无法关闭,原因?

时间:2011-12-06 18:24:21

标签: c++ glade gtkmm

为什么Gtk :: window的原因无法关闭?

我有一些错误的窗口,在创建仍然打开的对话框中无法关闭它们。一旦打开窗口关闭的对话框,它们就可以正常关闭......是一种策略行为。

在该应用程序的另一个版本中,我以相同的方式创建窗口,但是从主窗口可以关闭。

主窗口在main中创建,对话框在类扩展gtk :: window中创建,最后从对话框中创建无法关闭的两个窗口。

的main.cpp

#include "MainWindow.h"
#include <gtkmm/main.h>
#include <iostream>

int main(int argc, char *argv[]) {

    Gnome::Gda::init();
    Gtk::Main kit(argc, argv);

    Glib::RefPtr<Gtk::Builder> refBuilder = Gtk::Builder::create_from_file("MainWindow.glade");

    MainWindow *window;

    refBuilder->get_widget_derived("window1", window);
    Gtk::Main::run(*window);

    return 0;
}

MainWindow.cpp - &gt; class MainWindow:public Gtk :: Window

#include "MainWindow.h"
#include <libgdamm.h>
#include <gtkmm.h>
#include <iostream>
#include <fstream>
#include <memory>

#include "DBUtil.h"
#include "FormDialog.h"

MainWindow::MainWindow(BaseObjectType* cobject, Glib::RefPtr<Gtk::Builder> refBuilder) :
 Gtk::Window(cobject),
 m_refBuilder(refBuilder) {
//stuff
}
//more stuff
   void MainWindow::on_button_new() {
   FormDialog *dialog;

   Glib::RefPtr<Gtk::Builder> refBuilder = Gtk::Builder::create_from_file("FormDialog.glade");

   refBuilder->get_widget_derived("dialog1", dialog);
   dialog->setConnectionData(cnc, parser);
   dialog->run();

   delete dialog;

}
//even more stuff

FormDialog.cpp - &gt; class FormDialog:public Gtk :: Dialog

#include“FormDialog.h”

#include <gtkmm.h>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include "DBUtil.h"

FormDialog::FormDialog(BaseObjectType* cobject, Glib::RefPtr<Gtk::Builder> refBuilder) :
 Gtk::Dialog(cobject),
 m_refBuilder(refBuilder) {
 //stuff
}
//more stuff

int FormDialog::check_file(const char * path){
    if (strstr(path, ".jpg")!=NULL  || strstr(path, ".jpeg")!=NULL) 
    { return 1; }
    else {

Glib::ustring* us = new Glib::ustring("\n  Help \n");

Gtk::Window* help_win = new Gtk::Window(Gtk::WINDOW_TOPLEVEL);
help_win->set_title ("Help");
help_win->move(15,55);
Gtk::Label* lab = new Gtk::Label(*us,false);

    help_win->add(*lab);
    help_win->show_all();
    return 0; }
 }
 //More stuff
 void FormDialog::on_button_sel() {
 //function stuff
 if (check_file(dialog.get_filename().c_str())) {
 //more function stuff

 }

任何提示/线索/修复都将不胜感激!如果需要,我可以发布代码。 Thx提前

1 个答案:

答案 0 :(得分:0)

检查“FormDialog.glade”,如果对话框已设置为主窗口的瞬态并且property_modal为true,则在对话框首先退出之前,主窗口无法关闭。