[英]Gtkmm - Hiding a window without closing the application
How do i hide a toplevel window without closing it? 如何在不关闭窗口的情况下隐藏顶层窗口?
NdmWindow is a class inherited from Gtk::Window. NdmWindow是一个继承自Gtk :: Window的类。 I have added the instance of NdmWindow to Gtk::Application. 我已将NdmWindow的实例添加到Gtk :: Application。
Now, how do i hide it instead of closing it? 现在,我如何隐藏它而不是关闭它?
Thanks in advance.. 提前致谢..
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. 根据这个 ,行为是当一个窗口被隐藏时,它将从Gtk::Application
删除,因此如果它是最后一个窗口,则该应用程序退出。
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. 如果您希望应用程序在没有显示窗口时继续运行,解决方案是在您的Gtk::Application
对象上调用hold()
以增加Gtk::Application
的引用计数。 Presumably you do this before setting up any windows, and call the corresponding release()
as part of your quitting logic. 大概你在设置任何窗口之前这样做,并调用相应的release()
作为退出逻辑的一部分。
Here's a solution that works and doesn't segfault
. 下面是工作,不解决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
. 保存对Gtk::Application
的引用,比如将它作为param发送到你的主Window class
并调用这个var app
,稍后你需要它,因为在某些情况下get_application()
将返回null
。
In the delete event handler of your window call 在窗口调用的delete事件处理程序中
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. 当您想要再次显示窗口时,请不要调用app->release()
,因为它会使您的应用程序完全退出。 Just call set_visible()
on your window object and it will show up. 只需在窗口对象上调用set_visible()
,它就会显示出来。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.