[gtkmm] seg fault
- From: Neeraj Korde <nkorde umich edu>
- To: gtkmm-list gnome org
- Subject: [gtkmm] seg fault
- Date: Mon, 8 Sep 2003 18:34:50 -0400 (EDT)
well i can't find the bug here... its a simple constructor...
/////////////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_menu_file_new_generic();
virtual void on_btn_mat_open_clicked();
virtual void on_btn_open_clicked();
//Child widgets:
Gtk::VBox top_box;
Gtk::VBox file_box;
Gtk::Frame frm_open;
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);
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);
btn_mat_open.set_use_underline();
btn_mat_open.set_label("_Open");
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_children();
cout << "Done all\n";
}
I get a segmentation fault after the last line in constructor is executed.
i.e Done all appears on screen. The whole code for the 3 files is pasted
below. i am using gcc3.2.2 and gtkmm2.2.7, libsig 2.5
//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_menu_file_new_generic();
virtual void on_btn_mat_open_clicked();
virtual void on_btn_open_clicked();
//Child widgets:
Gtk::VBox top_box;
Gtk::VBox file_box;
Gtk::Frame frm_open;
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);
//file_open_box.set_border_width(5);
//file_open_box.set_layout(BUTTONBOX_START);
//file_open_box.set_spacing(30);
btn_open.set_use_underline();
//btn_open.add_pixlabel("info.xpm","_Open");
btn_open.set_label("_Open");
btn_open.signal_clicked().connect( SigC::slot(*this,
&ExampleWindow::on_btn_open_clicked));
//file_open_box.add(btn_open);
//file_open_box.add(lbl_filename);
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);
//mat_file_open_box.set_border_width(5);
//mat_file_open_box.set_layout(BUTTONBOX_START);
//mat_file_open_box.set_spacing(30);
btn_mat_open.set_use_underline();
//btn_mat_open.add_pixlabel("info.xpm","_Open");
btn_mat_open.set_label("_Open");
btn_mat_open.signal_clicked().connect( SigC::slot(*this,
&ExampleWindow::on_btn_mat_open_clicked));
//mat_file_open_box.add(btn_mat_open);
//mat_file_open_box.add(lbl_mat_filename);
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();
cout << "Done all\n";
}
ExampleWindow::~ExampleWindow()
{
}
void ExampleWindow::on_btn_open_clicked()
//standard open dialog from tutorials
{
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()
//standard open dialog from tutorial
{
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;
}
/////////////////////makefile////////////////////////////////
example: examplewindow.o main.o
g++ -o example examplewindow.o main.o `pkg-config gtkmm-2.0
--cflags --libs`
main.o: main.cc
g++ -c main.cc `pkg-config gtkmm-2.0 --cflags --libs`
examplewindow.o: examplewindow.cc examplewindow.h
g++ -c examplewindow.cc `pkg-config gtkmm-2.0 --cflags --libs`
///////////////////////////////////////////////
thanx!!!
Neeraj Korde
======================
Graduate Student
Mechanical Engineering
University of Michigan
======================
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]