Re: Running the main loop in a separate thread



Ok , this is driving me crazy - I wrote an example program just to try it and - yes - even if there's only one main loop in the simplest of applications the gtkmm window doesn't get destroyed before the process ( main() )ends . Now what's up with that ? Isn't there a way my application isn't all dependent on gtkmm (as in : can I , in normal circumstances , close my main window and have it disappear from the users view, before ending the program?) . Here's an example taken out of the tutorial on developer.gnome.org (not to bother you with my own messy code) (the only thing I added was sleep(2);). The app launches and on close the window doesn't disappear but hangs till the process ends:

class HelloWorld : public Gtk::Window
{

public:
  HelloWorld();
  virtual ~HelloWorld();

protected:
  //Signal handlers:
  void on_button_clicked();

  //Member widgets:
  Gtk::Button m_button;
};


HelloWorld::HelloWorld()
: m_button("Hello World") // creates a new button with label "Hello World".
{
  // Sets the border width of the window.
  set_border_width(10);

  // When the button receives the "clicked" signal, it will call the
  // on_button_clicked() method defined below.
  m_button.signal_clicked().connect(sigc::mem_fun(*this,
              &HelloWorld::on_button_clicked));

  // This packs the button into the Window (a container).
  add(m_button);

  // The final step is to display this newly created widget...
  m_button.show();
}

HelloWorld::~HelloWorld()
{
}

void HelloWorld::on_button_clicked()
{
  std::cout << "Hello World" << std::endl;

}



int main (int argc, char *argv[])
{
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "org.gtkmm.example");

  HelloWorld helloworld;

  //Shows the window and returns when it is closed.
  app->run(helloworld);

  sleep(2);
  return 0;
}


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