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 ...
随机推荐
- DWG 对象与ArcGIS 要素的强制对应关系
转自原文DWG 对象与ArcGIS 要素的强制对应关系 DWG 对象与ArcGIS 要素的强制对应关系如下: Feature type DWG object types Point Point, ...
- 【u239】整数分解
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 某些数能表示成为一些互不相同的整数的阶乘之和.如9=l!+2! +3!. 现在给定一个非负整数n,要求 ...
- BZOJ 2783 树 - 树上倍增 + 二分
传送门 分析: 对每个点都进行一次二分:将该点作为链的底端,二分链顶端所在的深度,然后倍增找到此点,通过前缀和相减求出链的权值,并更新l,r. code #include<bits/stdc++ ...
- NET媒体文件操作组件TagLib
开源的.NET媒体文件操作组件TagLib#解析 人生得意须尽欢 莫使金樽空对月.写博客都会在吃饭后,每次吃饭都要喝上二两小酒,写博客前都要闲扯,这些都是个人爱好,改不掉了,看不惯的人,还望多多包 ...
- Spring实战5-基于Spring构建Web应用
主要内容 将web请求映射到Spring控制器 绑定form参数 验证表单提交的参数 写在前面:关于Java Web,首先推荐一篇文章——写给java web一年左右工作经验的人,这篇文章的作者用精练 ...
- git与svn的不同
假设你在读这篇文章,说明你跟大多数开发人员一样对GIT感兴趣,假设你还没有机会来试一试GIT,我想如今你就要了解它了. GIT不不过个版本号控制系统,它也是个内容管理系统(CMS),工作管理系统等.假 ...
- webpack优化经验1(持续)
1 不知道该优化哪里 先开启gzip压缩,这样可以很直接的减少请求包的体积,效果显著,不过需要在服务器端作相应的配置才能生效 2拆分vendor包, 减少单体包的体积,并行加载 通过配置,将不同的公用 ...
- Android新闻案例clientserver达到,完全自己的新闻节目平台
一.建设新闻资料库 例如,下面的脚本代码:(正在使用mysql5.0 数据库) SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_z ...
- EM 12c: OMS Failed to start After restarting the Repository Database or reboot of the server
原文地址:http://blog.csdn.net/wanghui5767260/article/details/39398449 更全面,更专业 EM 12c: OMS Failed to star ...
- c#开发移动APP-Xamarin入门扩展剖析
原文:c#开发移动APP-Xamarin入门扩展剖析 上节将Phoneword应用程序扩展到包含第二个屏幕,该屏幕可以跟踪应用程序的拨打历史 Navigation Xamarin.Form提供了一个内 ...