LinuxSir.cn,穿越时空的Linuxsir!

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

[求助]新手Glade+Anjuta遇到问题

[复制链接]
发表于 2006-8-6 20:33:09 | 显示全部楼层 |阅读模式
用Glade设计界面并生成代码,用Anjuta编辑。就需要自己加两行button的click代码就行了,第二个俺不会,请帮忙看看。我用的Gtkmm.
window1_glade.hh
  1. // generated 2006/8/6 17:22:39 CST by bruce@Blueberry.(none)
  2. // using glademm V2.0.0.1
  3. //
  4. // DO NOT EDIT THIS FILE ! It was created using
  5. // glade-- /home/bruce/Projects/FirstApp/FirstApp.glade
  6. // for gtk 2.6.4 and gtkmm 2.2.12
  7. //
  8. // Please modify the corresponding derived classes in ./src/window1.hh and./src/window1.cc

  9. #ifndef _WINDOW1_GLADE_HH
  10. #  define _WINDOW1_GLADE_HH


  11. #if !defined(GLADEMM_DATA)
  12. #define GLADEMM_DATA
  13. #include <gtkmm/accelgroup.h>

  14. class GlademmData
  15. {  
  16.         
  17.         Glib::RefPtr<Gtk::AccelGroup> accgrp;
  18. public:
  19.         
  20.         GlademmData(Glib::RefPtr<Gtk::AccelGroup> ag) : accgrp(ag)
  21.         {  
  22.         }
  23.         
  24.         Glib::RefPtr<Gtk::AccelGroup>  getAccelGroup()
  25.         {  return accgrp;
  26.         }
  27. };
  28. #endif //GLADEMM_DATA

  29. #include <gtkmm/window.h>

  30. class window1_glade : public Gtk::Window
  31. {
  32. protected:      
  33.         GlademmData *gmm_data;
  34. protected:
  35.         
  36.         window1_glade();
  37.         
  38.         ~window1_glade();
  39. private:
  40.         virtual void on_button1_clicked() = 0;
  41.         virtual void on_button2_clicked() = 0;
  42. };
  43. #endif
复制代码

window1_glade.cc
  1. // generated 2006/8/6 17:22:39 CST by bruce@Blueberry.(none)
  2. // using glademm V2.0.0.1
  3. //
  4. // DO NOT EDIT THIS FILE ! It was created using
  5. // glade-- /home/bruce/Projects/FirstApp/FirstApp.glade
  6. // for gtk 2.6.4 and gtkmm 2.2.12
  7. //
  8. // Please modify the corresponding derived classes in ./src/window1.cc


  9. #if defined __GNUC__ && __GNUC__ < 3
  10. #error This program will crash if compiled with g++ 2.x
  11. // see the dynamic_cast bug in the gtkmm FAQ
  12. #endif //
  13. #include "config.h"
  14. #include "window1_glade.hh"
  15. #include <gdk/gdkkeysyms.h>
  16. #include <gtkmm/accelgroup.h>
  17. #include <gtkmm/label.h>
  18. #include <gtkmm/entry.h>
  19. #include <gtkmm/box.h>
  20. #include <gtkmm/image.h>
  21. #include <gtkmm/alignment.h>
  22. #include <gtkmm/button.h>

  23. window1_glade::window1_glade(
  24. ) : Gtk::Window(Gtk::WINDOW_TOPLEVEL)
  25. {  
  26.    
  27.    Gtk::Window *window1 = this;
  28.    gmm_data = new GlademmData(get_accel_group());
  29.    
  30.    Gtk::Label *inputLabel = Gtk::manage(new class Gtk::Label("这里的文字将随着输入变化"));
  31.    Gtk::Label *leftLabel = Gtk::manage(new class Gtk::Label("输入:"));
  32.    Gtk::Entry *inputEntry = Gtk::manage(new class Gtk::Entry());
  33.    Gtk::HBox *hbox1 = Gtk::manage(new class Gtk::HBox(false, 0));
  34.    Gtk::Image *image1 = Gtk::manage(new class Gtk::Image(Gtk::StockID("gtk-apply"), Gtk::IconSize(4)));
  35.    Gtk::Label *label3 = Gtk::manage(new class Gtk::Label("确认"));
  36.    Gtk::HBox *hbox3 = Gtk::manage(new class Gtk::HBox(false, 2));
  37.    Gtk::Alignment *alignment1 = Gtk::manage(new class Gtk::Alignment(0.5, 0.5, 0, 0));
  38.    Gtk::Button *button1 = Gtk::manage(new class Gtk::Button());
  39.    Gtk::Image *image2 = Gtk::manage(new class Gtk::Image(Gtk::StockID("gtk-quit"), Gtk::IconSize(4)));
  40.    Gtk::Label *label4 = Gtk::manage(new class Gtk::Label("退出"));
  41.    Gtk::HBox *hbox4 = Gtk::manage(new class Gtk::HBox(false, 2));
  42.    Gtk::Alignment *alignment2 = Gtk::manage(new class Gtk::Alignment(0.5, 0.5, 0, 0));
  43.    Gtk::Button *button2 = Gtk::manage(new class Gtk::Button());
  44.    Gtk::HBox *hbox2 = Gtk::manage(new class Gtk::HBox(false, 0));
  45.    Gtk::VBox *vbox1 = Gtk::manage(new class Gtk::VBox(false, 0));
  46.    inputLabel->set_alignment(0.5,0.5);
  47.    inputLabel->set_padding(0,0);
  48.    inputLabel->set_justify(Gtk::JUSTIFY_CENTER);
  49.    inputLabel->set_line_wrap(false);
  50.    inputLabel->set_use_markup(false);
  51.    inputLabel->set_selectable(false);
  52.    leftLabel->set_alignment(0.5,0.5);
  53.    leftLabel->set_padding(0,0);
  54.    leftLabel->set_justify(Gtk::JUSTIFY_LEFT);
  55.    leftLabel->set_line_wrap(false);
  56.    leftLabel->set_use_markup(false);
  57.    leftLabel->set_selectable(false);
  58.    inputEntry->set_flags(Gtk::CAN_FOCUS);
  59.    inputEntry->set_visibility(true);
  60.    inputEntry->set_editable(true);
  61.    inputEntry->set_max_length(0);
  62.    inputEntry->set_text("");
  63.    inputEntry->set_has_frame(true);
  64.    inputEntry->set_activates_default(false);
  65.    hbox1->pack_start(*leftLabel, Gtk::PACK_SHRINK, 2);
  66.    hbox1->pack_start(*inputEntry, Gtk::PACK_EXPAND_WIDGET, 2);
  67.    image1->set_alignment(0.5,0.5);
  68.    image1->set_padding(0,0);
  69.    label3->set_alignment(0.5,0.5);
  70.    label3->set_padding(0,0);
  71.    label3->set_justify(Gtk::JUSTIFY_LEFT);
  72.    label3->set_line_wrap(false);
  73.    label3->set_use_markup(false);
  74.    label3->set_selectable(false);
  75.    hbox3->pack_start(*image1, Gtk::PACK_SHRINK, 0);
  76.    hbox3->pack_start(*label3, Gtk::PACK_SHRINK, 0);
  77.    alignment1->add(*hbox3);
  78.    button1->set_flags(Gtk::CAN_FOCUS);
  79.    button1->set_border_width(2);
  80.    button1->set_relief(Gtk::RELIEF_NORMAL);
  81.    button1->add(*alignment1);
  82.    image2->set_alignment(0.5,0.5);
  83.    image2->set_padding(0,0);
  84.    label4->set_alignment(0.5,0.5);
  85.    label4->set_padding(0,0);
  86.    label4->set_justify(Gtk::JUSTIFY_LEFT);
  87.    label4->set_line_wrap(false);
  88.    label4->set_use_markup(false);
  89.    label4->set_selectable(false);
  90.    hbox4->pack_start(*image2, Gtk::PACK_SHRINK, 0);
  91.    hbox4->pack_start(*label4, Gtk::PACK_SHRINK, 0);
  92.    alignment2->add(*hbox4);
  93.    button2->set_flags(Gtk::CAN_FOCUS);
  94.    button2->set_border_width(2);
  95.    button2->set_relief(Gtk::RELIEF_NORMAL);
  96.    button2->add(*alignment2);
  97.    hbox2->pack_start(*button1, Gtk::PACK_SHRINK, 40);
  98.    hbox2->pack_start(*button2, Gtk::PACK_SHRINK, 40);
  99.    vbox1->pack_start(*inputLabel, Gtk::PACK_SHRINK, 4);
  100.    vbox1->pack_start(*hbox1, Gtk::PACK_EXPAND_WIDGET, 2);
  101.    vbox1->pack_start(*hbox2, Gtk::PACK_EXPAND_WIDGET, 2);
  102.    window1->set_border_width(2);
  103.    window1->set_title("我的第一个Gnome程序");
  104.    window1->set_default_size(500,400);
  105.    window1->set_modal(false);
  106.    window1->property_window_position().set_value(Gtk::WIN_POS_NONE);
  107.    window1->set_resizable(false);
  108.    window1->property_destroy_with_parent().set_value(false);
  109.    window1->add(*vbox1);
  110.    inputLabel->show();
  111.    leftLabel->show();
  112.    inputEntry->show();
  113.    hbox1->show();
  114.    image1->show();
  115.    label3->show();
  116.    hbox3->show();
  117.    alignment1->show();
  118.    button1->show();
  119.    image2->show();
  120.    label4->show();
  121.    hbox4->show();
  122.    alignment2->show();
  123.    button2->show();
  124.    hbox2->show();
  125.    vbox1->show();
  126.    window1->show();
  127.    button1->signal_clicked().connect(SigC::slot(*this, &window1_glade::on_button1_clicked));
  128.    button2->signal_clicked().connect(SigC::slot(*this, &window1_glade::on_button2_clicked));
  129. }

  130. window1_glade::~window1_glade()
  131. {  delete gmm_data;
  132. }
复制代码

window1.h
  1. // generated 2006/8/6 17:13:28 CST by bruce@Blueberry.(none)
  2. // using glademm V2.0.0.1
  3. //
  4. // newer (non customized) versions of this file go to window1.hh_new

  5. // you might replace
  6. //    class foo : public foo_glade { ... };
  7. // by
  8. //    typedef foo_glade foo;
  9. // if you didn't make any modifications to the widget

  10. #ifndef _WINDOW1_HH
  11. #  include "window1_glade.hh"
  12. #  define _WINDOW1_HH
  13. class window1 : public window1_glade
  14. {
  15. protected:
  16.         virtual void on_button1_clicked();
  17.         virtual void on_button2_clicked();
  18. };
  19. #endif
复制代码

window1.cc

  1. // generated 2006/8/6 17:13:28 CST by bruce@Blueberry.(none)
  2. // using glademm V2.0.0.1
  3. //
  4. // newer (non customized) versions of this file go to window1.cc_new

  5. // This file is for your program, I won't touch it again!

  6. #include "config.h"
  7. #include "window1.hh"
  8. #include <gtkmm/main.h>
  9. #include <gtkmm/label.h>
  10. #include <gtkmm/entry.h>

  11. void window1::on_button1_clicked()
  12. {
  13.         ?????
  14. }

  15. void window1::on_button2_clicked()
  16. {
  17.         Gtk::Main::quit();
  18. }

复制代码

================
我想点一下确认按钮,在顶上的label上显示entry里的文字。那个gmm_data是个什么东东,就那里搞不明白,而且是private的。
初学,迫切的想写出第一个程序来,有些文档什么的来不及看,请勿见怪,谢谢![/img]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
 楼主| 发表于 2006-8-8 10:00:06 | 显示全部楼层
真晕哪!用Emacs一点一点的写是可以达到目的的,就是太累!
哪位大侠来指导一下啊?
谢谢!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-8-8 22:30:13 | 显示全部楼层
已经解决。。。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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