LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 788|回复: 0

[求助]libglademm的问题

[复制链接]
发表于 2008-7-29 16:34:24 | 显示全部楼层 |阅读模式
我在用gtkmm/libglademm编程的时候遇到了一个奇怪问题,可能是libglademm的一个BUG,请大家帮忙看看解决办法。

问题如下:

我要让程序在按下“关于”按钮时显示“关于”对话框。
我先定义
Gtk::AboutDialog *gp_about_dialog;
,再用Gnome::Glade::Xml的get_widget方法来取得AboutDialog。
m_refGlade->get_widget("gp_about_dialog", gp_about_dialog);

程序编译没有问题,但是在运行时却出错了。出错信息如下:
  1. (gpppoe:7858): libglademm-CRITICAL **: widget `gp_about_dialog' not found in glade file `gpppoe.glade'
  2. ** (gpppoe:7858): CRITICAL **: Gnome::Glade::Xml::get_widget(): dynamic_cast<> failed.
复制代码

但是glade文件中明明是有gp_about_dialog的呀,而且在取得其它的窗口时没有问题,只有在取得Gtk::AboutDialog时出错。
是我程序写错了,还是libglademm本身的问题?

我在网上搜索了一下,发现有人也碰到过这个问题。
http://osdir.com/ml/gnome.gnomemm/2005-08/msg00005.html
那人写道:
After a bit of research and experimentation, it would seem that the
problem lies in the way libglademm handles the <child
internal-child="vbox"> tags, inside widgets derrived from GtkDialog.

我发现Gtk::AboutDialog的确有一个内部的vbox类。真的是这里出的问题吗?有何解决方法?

附上源代码:
MainWindow.hpp

  1. #ifndef _MAINWINDOW_HPP_
  2. #define _MAINWINDOW_HPP_

  3. #include <gtkmm.h>
  4. #include <libglademm.h>
  5. //#include <libglademm/xml.h>         //Load widgets from glade file
  6. #include <libglademm/variablesmap.h>   //connect widgets and variables
  7. #include <sigc++/functors/slot.h>         //signal slots

  8. class MainWindow: public Gtk::Window
  9. {
  10. public:
  11.         MainWindow(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& refGlade);
  12.         virtual ~MainWindow();
  13.         static MainWindow* create();
  14.        
  15.         Gtk::Button *gp_button_connect;

  16. protected:
  17.         Glib::RefPtr<Gnome::Glade::Xml> m_refGlade;
  18.         Gtk::Button *gp_button_about;
  19.         Gtk::Button *gp_button_quit;
  20.         Gtk::AboutDialog *gp_about_dialog;

  21.         //Signal handlers:
  22.         virtual void on_button_quit();
  23.         void on_gp_button_about_clicked();


  24. };

  25. #endif // _MAINWINDOW_HPP_

复制代码


MainWindow.cpp

  1. #include <iostream>
  2. #include "MainWindow.hpp"
  3. #include <glibmm.h>
  4. #include <giomm.h>

  5. #define GLADE_FILE "gpppoe.glade"
  6. #define GLADE_NAME "gp_main_window"

  7. MainWindow::MainWindow (BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& refGlade)
  8. : Gtk::Window(cobject),
  9.   m_refGlade(refGlade),
  10.   gp_button_about(0),
  11.   gp_about_dialog(0)
  12. {
  13.         //Get the Glade-instantiated Button, and connect a signal handler:
  14.         m_refGlade->get_widget("gp_button_about", gp_button_about);
  15.         gp_button_about->signal_clicked().connect( sigc::mem_fun(*this, &MainWindow::on_gp_button_about_clicked));
  16.        
  17.         m_refGlade->get_widget("gp_button_quit", gp_button_quit);
  18.         gp_button_quit->signal_clicked().connect( sigc::mem_fun(*this, &MainWindow::on_button_quit));
  19.        
  20.         m_refGlade->get_widget("gp_button_connect", gp_button_connect);
  21.         //Signal handlers:
  22.        
  23. }

  24. MainWindow::~MainWindow()
  25. {
  26.        
  27. }

  28. MainWindow* MainWindow::create() {
  29.     MainWindow *w = NULL;
  30.     Glib::RefPtr<Gnome::Glade::Xml> refXml = Gnome::Glade::Xml::create(GLADE_FILE, GLADE_NAME);
  31.     refXml->get_widget_derived(GLADE_NAME, w);
  32.     return w;
  33. }

  34. void MainWindow::on_button_quit () {
  35.         hide();
  36. }

  37. void MainWindow::on_gp_button_about_clicked() {
  38.     gp_about_dialog = 0;
  39.         m_refGlade->get_widget("gp_about_dialog", gp_about_dialog);
  40.     if (gp_about_dialog)
  41.     {
  42.             //std::cout << "gp_about_dialog" << std::endl;                //for test
  43.             gp_about_dialog->show();
  44.     }
  45. }

复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表