stupid segfaults -- argh!
- From: "Joe Van Dyk" <joevandyk gmail com>
- To: gtkmm-list gnome org
- Subject: stupid segfaults -- argh!
- Date: Mon, 5 Jun 2006 15:37:20 -0700
Any ideas why this segfaults? Any ideas on how to fix it?
Thanks,
Joe
#include <gtkmm.h>
#include <iostream>
#include <string>
struct GUI : public Gtk::Window
{
Gtk::Label label;
std::string text;
GUI()
{
text = "Sup";
set_title("Application Title");
resize(300, 300);
label.set_text("Label title");
add(label);
show_all();
}
void start()
{
std::cerr << "Before start()" << std::endl;
Gtk::Main::run(*this);
std::cerr << "After start()" << std::endl;
}
void update(const std::string &input)
{
label.set_text(input);
}
};
struct Program
{
// Has to be a pointer? Because I can't call Gtk::main
// before I construct the GUI?
GUI *gui;
void initialize(int argc, char *argv[])
{
Glib::thread_init();
Gtk::Main kit(argc, argv);
gui = new GUI();
Glib::Thread *gui_thread = Glib::Thread::create(sigc::mem_fun(*gui,
&GUI::start), true);
// This function needs to return -- can't join on thread
}
void update(const std::string &input)
{
gui->update(input);
}
void shutdown()
{
std::cerr << "shutdown" << std::endl;
}
};
// I can't change main(). So, Glib::thread_init() and company needs to be done
// in the above class' constructor. But that causes problems...
int main(int argc, char *argv[])
{
Program program;
program.initialize(argc, argv);
std::string input;
while(true)
{
std::cout << "\n\nType in something cool: ";
while (std::getline(std::cin, input))
program.update(input);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]