Reputation: 223
How do i hide a toplevel window without closing it?
NdmWindow is a class inherited from Gtk::Window. I have added the instance of NdmWindow to Gtk::Application.
Now, how do i hide it instead of closing it?
Thanks in advance..
Upvotes: 3
Views: 3220
Reputation: 214
Here's a solution that works and doesn't segfault
.
Save a reference to Gtk::Application
, say send it as a param to your main Window class
and call this var app
, you'll need it later, it's needed because in some cases get_application()
will return null
.
In the delete event handler of your window call
app->hold();
hide();
return true;
Don't call app->release()
when you want to make your window show up again since it will make your application exit completely. Just call set_visible()
on your window object and it will show up.
Upvotes: 2
Reputation: 49019
According to this, the behavior is that when a window is hidden, it is removed from Gtk::Application
, and so if it is the last window, the app quits.
If you want your application to keep running when no windows are showing, the solution is to call hold()
on your Gtk::Application
object to increase the reference count of the application. Presumably you do this before setting up any windows, and call the corresponding release()
as part of your quitting logic.
Upvotes: 8