qt窗体close和hide的区别

qt窗体close和hide的区别,第1张

bool QWidget::close() [slot]

Closes this widget Returns true if the widget was closed; otherwise returns false

First it sends the widget a QCloseEvent The widget is hidden if it accepts the close event If it ignores the event, nothing happens The default implementation of QWidget::closeEvent() accepts the close event

If the widget has the Qt::WA_DeleteOnClose flag, the widget is also deleted A close events is delivered to the widget no matter if the widget is visible or not

The QApplication::lastWindowClosed() signal is emitted when the last visible primary window (ie window with no parent) with the Qt::WA_QuitOnClose attribute set is closed By default this attribute is set for all widgets except transient windows such as splash screens, tool windows, and popup menus

上面是qt assistant关于QWidget类的close槽的说明。

关闭widget。如果widget被关闭返回true,否则返回false。

它首先向widget发送QCloseEvent事件。如果窗体接收到close事件就隐藏。如果它忽略了该事件,就什么都不会发生。QWidget::closeEvent()的默认实现接收close事件。

如果widget有Qt::WA_DeleteOnClose标志,则widget也会被删除。无论widget是否可见close事件都会投递到widget。

当最后一个带有Qt::WA_QuitOnClose属性的可见主窗口被关闭时,会发送QApplication::lastWindowClosed()信号。该属性默认所有widget都有,除了splash screens, tool windows, and popup menus这些临时窗体。

void QWidget::hide() [slot]

Hides the widget This function is equivalent to setVisible(false)

隐藏widget。该函数等同于 setVisible(false)。

那么close和hide区别就很明显了:

hide只是隐藏窗体。不会发送任何信号。

close一般也是隐藏窗口。但是它会发送QCloseEvent事件。你可以重写void QWidget::closeEvent(QCloseEvent event) [virtual protected],可以隐藏widget或者不隐藏。Qt::WA_DeleteOnClose标志还会影响窗体在内存中的状态,如果设置了该标志,窗体就会被删除,而hide则不会。最后主窗体的close会导致整个程序的退出,而hide明显不会。

free从内存中释放。

terminate强制终止程序,有些东东可能来不及从内存中释放。

hide隐藏,但仍在内存中。

close其结果要看你当初设置,有的如hide有的如free;

不想被管理员从控制面板中的添加删除程序里

发现蛛丝马迹吧。请看下文:

在C:\Windows\Inf下找到Sysocinf文件,用记事本程序打开它,

该文件显示了当前已安装程序的部分列表。

我们拿

msn

来做个实验,在其中找到这一句

“msmsgs=msgrocmdll,OcEntry,msmsgsinf,hide,7”,

其中“msmsgs”是MSN

Messenger的条目名,

“hide”这个参数就是控制着程序是否在“添加/删除程序”中显示,

我们只要把它删除,变为“msmsgs=msgrocmdll,OcEntry,msmsgsinf,,7”,

然后重新启动电脑,再次到“添加/删除程序”中,就会看到MSN

Messenger了。

根据这个道理,可以把Sysocinf文件中包含的“hide”全部删除,

这样那些被隐藏的组件就都会在“添加/删除程序”中全部显示出来了。

我想,我写个些东东,并不是为了显示吧,呵呵。当然,反之,我们加上了hide这一句就隐藏了噻

以上就是关于qt窗体close和hide的区别全部的内容,包括:qt窗体close和hide的区别、free,terminate,hide,和close的区别是什么、怎么通过修改注册表让添加/删除程序里不显示某些应用程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/9768594.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-01
下一篇 2023-05-01

发表评论

登录后才能评论

评论列表(0条)

保存