[gtkmm-documentation] Application/app_and_win_menus example: Hide the window when quitting



commit ada1f833c11d89200fe75cea4217f5150b4098c8
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Fri Jun 6 18:20:38 2014 +0200

    Application/app_and_win_menus example: Hide the window when quitting
    
    * examples/book/application/app_and_win_menus/exampleapplication.cc:
    Hide the window in on_action_quit(). Add a comment that explains why this
    is done. Bug #731126.

 .../app_and_win_menus/exampleapplication.cc        |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)
---
diff --git a/examples/book/application/app_and_win_menus/exampleapplication.cc 
b/examples/book/application/app_and_win_menus/exampleapplication.cc
index 87c5e43..eaf0e93 100644
--- a/examples/book/application/app_and_win_menus/exampleapplication.cc
+++ b/examples/book/application/app_and_win_menus/exampleapplication.cc
@@ -123,7 +123,18 @@ void ExampleApplication::on_action_something()
 void ExampleApplication::on_action_quit()
 {
   std::cout << G_STRFUNC << std::endl;
-  quit();
+  quit(); // Not really necessary, when Gtk::Widget::hide() is called.
+
+  // Gio::Application::quit() will make Gio::Application::run() return,
+  // but it's a crude way of ending the program. The window is not removed
+  // from the application. Neither the window's nor the application's
+  // destructors will be called, because there will be remaining reference
+  // counts in both of them. If we want the destructors to be called, we
+  // must remove the window from the application. One way of doing this
+  // is to hide the window.
+  std::vector<Gtk::Window*> windows = get_windows();
+  if (windows.size() > 0)
+    windows[0]->hide(); // In this simple case, we know there is only one window.
 }
 
 void ExampleApplication::on_action_print(const Glib::VariantBase& parameter)


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