[gtkmm] button properties



Could u tell me what's wrong here... i am just packing a button and a
label in an HBox,
putting 2 such HBoxes in a VBox, putting that VBox in a frame which in
turn goes in
a VBox. I am getting seg faults on what shud have been a simple program.
Thanx!

*******************************examplewindow.h*************************************
#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H
#include <gtkmm/window.h>
#include <gtkmm/box.h>
#include <gtkmm.h>

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:
  //Signal handlers:
  virtual void on_btn_mat_open_clicked();
  virtual void on_btn_open_clicked();

  //Child widgets:
  Gtk::VBox top_box;
  Gtk::Frame frm_open;
  Gtk::VBox file_box;
	Gtk::HBox file_open_box;
  	Gtk::Button btn_open; Gtk::Label lbl_filename;

	Gtk::HBox mat_file_open_box;
	Gtk::Button btn_mat_open; Gtk::Label lbl_mat_filename;

  //data for problem
  std::string filename;
  std::string mat_filename;
};

#endif //GTKMM_EXAMPLEWINDOW_H


***********************************examplewindow.cc****************************
#include "examplewindow.h"
#include <gtkmm/stock.h>
#include <iostream>

using namespace std;
using namespace Gtk;

ExampleWindow::ExampleWindow()
:top_box(false,10),
frm_open("File Open"),
file_box(false,30),
file_open_box(false,30),
mat_file_open_box(false,30),
lbl_filename("/blah/blah"),
btn_mat_open("Open Matrix File"),
lbl_mat_filename("blah/blah")
{
  set_title("Deval");

  add(top_box);
  top_box.pack_start(frm_open,PACK_SHRINK);
  frm_open.add(file_box);

  file_box.pack_start(file_open_box, PACK_SHRINK);

  btn_open.set_use_underline();
  btn_open.set_label("_Open");
  btn_open.signal_clicked().connect( SigC::slot(*this,
&ExampleWindow::on_btn_open_clicked));
  file_open_box.pack_start(btn_open,PACK_SHRINK);
  file_open_box.pack_start(lbl_filename,PACK_SHRINK);

  file_box.pack_start(mat_file_open_box,PACK_SHRINK);

  btn_mat_open.set_use_underline();
  btn_mat_open.set_label("_Open Matrix File");
  btn_mat_open.signal_clicked().connect( SigC::slot(*this,
&ExampleWindow::on_btn_mat_open_clicked));
  mat_file_open_box.pack_start(btn_mat_open,PACK_SHRINK);
  mat_file_open_box.pack_start(lbl_mat_filename,PACK_SHRINK);

  //show all
  show_all_children();
}

ExampleWindow::~ExampleWindow()
{
}
//standard file selection dialogs cut and pasted from tutorials...
void ExampleWindow::on_btn_open_clicked()
{
	Gtk::FileSelection dialog("Open file");
	dialog.set_transient_for(*this);
	int result = dialog.run();

	//Handle the response:
	switch(result)
	{
		case(Gtk::RESPONSE_OK):
		{
			std::cout << "OK clicked." << std::endl;
			filename = dialog.get_filename(); //Notice that it
is a std::string, not a Glib::ustring.
			lbl_filename.set_text(filename);
			std::cout << "File selected: " <<  filename <<
std::endl;
      			break;
    		}
		case(Gtk::RESPONSE_CANCEL):
    		{
      			std::cout << "Cancel clicked." << std::endl;
      			break;
    		}
    		default:
    		{
      			std::cout << "Unexpected button clicked." <<
std::endl;
      			break;
 		}
  	}
}

void ExampleWindow::on_btn_mat_open_clicked()
{
	Gtk::FileSelection dialog("Open file");
	dialog.set_transient_for(*this);
	int result = dialog.run();

	//Handle the response:
	switch(result)
	{
		case(Gtk::RESPONSE_OK):
		{
			std::cout << "OK clicked." << std::endl;
			mat_filename = dialog.get_filename(); //Notice
that it is a std::string, not a Glib::ustring.
			lbl_mat_filename.set_text(mat_filename);
			std::cout << "File selected: " <<  mat_filename <<
std::endl;
			break;
    		}
		case(Gtk::RESPONSE_CANCEL):
    		{
      			std::cout << "Cancel clicked." << std::endl;
      			break;
    		}
    		default:
    		{
      			std::cout << "Unexpected button clicked." <<
std::endl;
      			break;
    		}
  	}
}

**********************************main.cc*****************************************
#include <gtkmm/main.h>
#include "examplewindow.h"

int main(int argc, char *argv[])
{
  Gtk::Main kit(argc, argv);

  ExampleWindow window;
  Gtk::Main::run(window); //Shows the window and returns when it is
closed.

  return 0;
}



Neeraj Korde
======================
Graduate Student
Mechanical Engineering
University of Michigan
======================






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]