QDialog在hide()之后,就被销毁的原因
一路跟踪源码,关键就是这两句:
int QDialog::exec()
{
Q_D(QDialog); if (d->eventLoop) {
qWarning("QDialog::exec: Recursive call detected");
return -;
} bool deleteOnClose = testAttribute(Qt::WA_DeleteOnClose);
setAttribute(Qt::WA_DeleteOnClose, false); d->resetModalitySetByOpen(); bool wasShowModal = testAttribute(Qt::WA_ShowModal);
setAttribute(Qt::WA_ShowModal, true);
setResult(); show(); QPointer<QDialog> guard = this;
if (d->nativeDialogInUse) {
d->platformHelper()->exec();
} else {
QEventLoop eventLoop;
d->eventLoop = &eventLoop;
(void) eventLoop.exec(QEventLoop::DialogExec);
}
if (guard.isNull())
return QDialog::Rejected;
d->eventLoop = ; setAttribute(Qt::WA_ShowModal, wasShowModal); int res = result();
if (d->nativeDialogInUse)
d->helperDone(static_cast<QDialog::DialogCode>(res), d->platformHelper());
if (deleteOnClose)
delete this;
return res;
} void QWidget::hide()
{
setVisible(false);
} void QDialog::setVisible(bool visible)
{
Q_D(QDialog);
if (!testAttribute(Qt::WA_DontShowOnScreen) && d->canBeNativeDialog() && d->setNativeDialogVisible(visible))
return; if (visible) {
if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden))
return; QWidget::setVisible(visible);
showExtension(d->doShowExtension);
QWidget *fw = window()->focusWidget();
if (!fw)
fw = this; /*
The following block is to handle a special case, and does not
really follow propper logic in concern of autoDefault and TAB
order. However, it's here to ease usage for the users. If a
dialog has a default QPushButton, and first widget in the TAB
order also is a QPushButton, then we give focus to the main
default QPushButton. This simplifies code for the developers,
and actually catches most cases... If not, then they simply
have to use [widget*]->setFocus() themselves...
*/
if (d->mainDef && fw->focusPolicy() == Qt::NoFocus) {
QWidget *first = fw;
while ((first = first->nextInFocusChain()) != fw && first->focusPolicy() == Qt::NoFocus)
;
if (first != d->mainDef && qobject_cast<QPushButton*>(first))
d->mainDef->setFocus();
}
if (!d->mainDef && isWindow()) {
QWidget *w = fw;
while ((w = w->nextInFocusChain()) != fw) {
QPushButton *pb = qobject_cast<QPushButton *>(w);
if (pb && pb->autoDefault() && pb->focusPolicy() != Qt::NoFocus) {
pb->setDefault(true);
break;
}
}
}
if (fw && !fw->hasFocus()) {
QFocusEvent e(QEvent::FocusIn, Qt::TabFocusReason);
QApplication::sendEvent(fw, &e);
} #ifndef QT_NO_ACCESSIBILITY
QAccessibleEvent event(this, QAccessible::DialogStart);
QAccessible::updateAccessibility(&event);
#endif } else {
if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden))
return; #ifndef QT_NO_ACCESSIBILITY
if (isVisible()) {
QAccessibleEvent event(this, QAccessible::DialogEnd);
QAccessible::updateAccessibility(&event);
}
#endif // Reimplemented to exit a modal event loop when the dialog is hidden.
QWidget::setVisible(visible);
if (d->eventLoop)
d->eventLoop->exit();
} const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme();
if (d->mainDef && isActiveWindow()
&& theme->themeHint(QPlatformTheme::DialogSnapToDefaultButton).toBool())
QCursor::setPos(d->mainDef->mapToGlobal(d->mainDef->rect().center()));
}
QDialog在hide()之后,就被销毁的原因的更多相关文章
- web前端常用小函数汇总
//去掉html标签 function delHtmlTag(str) { var title = str.replace(/<[^>]+>/g, "");// ...
- Jquery分页组件
最近工作不是很忙,所以就看看淘宝kissy分页组件源码,感觉代码也不怎么难 容易理解,所以就按照他们的思路自己重新理一遍,来加深自己对他们的理解,同时对他们的分页组件进行一些重构(因为他们分页是做好了 ...
- JQuery+Bootstrap 自定义全屏Loading插件
/** * 自定义Loading插件 * @param {Object} config * { * content[加载显示文本], * time[自动关闭等待时间(ms)] * } * @param ...
- 10 Cookie/Session
JSP/EL入门 * SUN提供了开发WEB资源的技术 Servlet/JSP * response.getWriter().write(); ...
- 使用UIKit制作卡牌游戏(一)ios游戏篇
转自朋友Tommy 的翻译,自己只翻译了第三篇教程. 译者: Tommy | 原文作者: Matthijs Hollemans写于2012/06/29 原文地址: http://www.raywend ...
- 再次讲解js中的回收机制是怎么一回事。
在前几天的一篇闭包文章中我们简单的介绍了一下闭包,但是并没有深入的讲解,因为闭包涉及的知识点比较多,为了能够更好的理解闭包,今天讲解一下关于js中的回收机制. 在初识闭包一文中我说过js中有回收机制这 ...
- javascript js 内存泄露
JavaScript 内存泄露 1.什么是闭包.以及闭包所涉及的作用域链这里就不说了. 2.JavaScript垃圾回收机制 JavaScript不需要手动地释放内存,它使用一种自动垃圾回收机制(ga ...
- JavaScript 中的内存泄漏
JavaScript 中的内存泄漏 JavaScript 是一种垃圾收集式语言,这就是说,内存是根据对象的创建分配给该对象的,并会在没有对该对象的引用时由浏览器收回.JavaScript 的垃圾收集机 ...
- Irrlicht 3D Engine 笔记系列 之 自己定义Animator
作者: i_dovelemon 日期: 2014 / 12 / 17 来源: CSDN 主题: Custom Animator, Referenced count 引言 在昨天的文章<Irrli ...
随机推荐
- activiti自己定义流程之整合(五):启动流程时获取自己定义表单
流程定义部署之后,自然就是流程定义列表了,但和前一节一样的是,这里也是和之前单独的activiti没什么差别.因此也不多说.我们先看看列表页面以及相应的代码,然后在一步步说明点击启动button时怎样 ...
- boost1.59编译安装(可以完全安装,也可定制安装--buildtype=complete,link=static)
1.下载: 网址:http://sourceforge.net/projects/boost/files/boost/1.59.0/ 选择:boost_1_59_0.7z或者boost_1_59_0. ...
- uitableview顶部多出20距离, UIScollView顶部多出64距离
self.automaticallyAdjustsScrollViewInsets = NO;看 这个UIViewController的这个属性你就明白了,此属性默认为YES,这样UIViewCont ...
- HDU 1422 重温世界杯 - 贪心
传送门 题目大意: 给一串数,又正有负,求每一个前缀都大于0的最长子串长度. 题目分析: 直接贪心:每次左端点向右推1,不断延伸右端点,更新答案. code #include<bits/stdc ...
- 每天一个JavaScript实例-铺货鼠标点击位置并将元素移动到该位置
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- 一起学Python:字符串介绍
字符串介绍 <1>python中字符串的格式 如下定义的变量a,存储的是数字类型的值 a = 100 如下定义的变量b,存储的是字符串类型的值 b = "hello itcast ...
- 调用cordova相关插件进行消息推送(通知栏提醒、响铃、震动)
原文:调用cordova相关插件进行消息推送(通知栏提醒.响铃.震动) 版权声明:本文为博主原创文章,转载须注明出处,博客地址:https://blog.csdn.net/wx13227855087 ...
- Java开发环境安装,环境变量
下载地址:www.oracle.com Java 9下载地址:https://www.oracle.com/technetwork/java/javase/downloads/java-archive ...
- 浏览器加载js文件顺序
在默认情况下,下载和执行js都会阻塞页面的渲染,当然现在浏览器支持并行下载,但仍然会阻塞图片等的下载和渲染,所以通常建议把js文件放body底.对于执行顺序,不管是外部js还是内部,只要 遇到< ...
- Windows下JDK开发环境搭建及环境变量配置
1.下载并安装Java开发工具包(JDK) 下载地址: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2 ...