0

I've written an event event handler for my window's File->Quit button:

void on_file_quit() {
  int err = pthread_cancel( work ); 
  if (err) {
     std::cerr << "no thread to cancel\n";
  }
  else { 
    pthread_join( work, NULL );
  }
}

instantiating it this way:

pfile_quit->signal_activate().connect( sigc::ptr_fun(on_file_quit) );

I would like to make then close the window at the end of on_file_quit(), as in pressing the close button at the top of the window. I haven't found the solution anywhere. Thanks in advance for any help!

rodrigo
  • 94,151
  • 12
  • 143
  • 190
tweaksp
  • 601
  • 5
  • 14
  • According to [this](http://zetcode.com/tutorials/gtktutorial/gtkevents/), pressing the X button at the top of the window sends `destroy` signal. Send that signal or just call it's handler directly. – Piotr Praszmo Jul 10 '12 at 19:16
  • I've read this post... I'm new to GTK. I don't know how to *cause* this signal. – tweaksp Jul 10 '12 at 20:32
  • Ok, after looking around for a way to send a widget the destroy signal, I came up short. My solution was to call the window's destructor ... this seems to work cleanly. I'll post the change when stackoverflow allows me too. – tweaksp Jul 10 '12 at 21:19

2 Answers2

0

You can close the window with Gtk::Widget::hide(). If you want to do the same thing that would happen when the X button is clicked (which sends the delete_event signal), just call your on_delete_event() handler directly.

By the way, you are not "instantiating" a signal handler. You are connecting a signal handler. Also, this is gtkmm, not GTK+.

murrayc
  • 2,103
  • 4
  • 17
  • 32
0

Thanks for your reply. Would calling Gtk::Widget::hide() close the window so that I can exit the application? My solution was simply to call the window's destructor, like so:

void on_file_quit() {
  int err = pthread_cancel( work ); 
  if (err) {
     std::cerr << "no thread to cancel\n";
  }
  else { 
    pthread_join( work, NULL );
  }
  delete pwindow;
  pwindow = NULL; 
}

Then I connected this handler to the x button:

 g_signal_connect (pwindow->gobj(), "delete_event", G_CALLBACK (on_file_quit), NULL);

I couldn't figure out how to do this in gtkmm. I'm satisfied with this solution, but I don't know that it is the safest/most standard.

This worked too: pwindow->hide().

tweaksp
  • 601
  • 5
  • 14