一路跟踪源码,关键就是这两句:

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()之后,就被销毁的原因的更多相关文章

  1. web前端常用小函数汇总

    //去掉html标签 function delHtmlTag(str) { var title = str.replace(/<[^>]+>/g, "");// ...

  2. Jquery分页组件

    最近工作不是很忙,所以就看看淘宝kissy分页组件源码,感觉代码也不怎么难 容易理解,所以就按照他们的思路自己重新理一遍,来加深自己对他们的理解,同时对他们的分页组件进行一些重构(因为他们分页是做好了 ...

  3. JQuery+Bootstrap 自定义全屏Loading插件

    /** * 自定义Loading插件 * @param {Object} config * { * content[加载显示文本], * time[自动关闭等待时间(ms)] * } * @param ...

  4. 10 Cookie/Session

    JSP/EL入门     * SUN提供了开发WEB资源的技术     Servlet/JSP              * response.getWriter().write();         ...

  5. 使用UIKit制作卡牌游戏(一)ios游戏篇

    转自朋友Tommy 的翻译,自己只翻译了第三篇教程. 译者: Tommy | 原文作者: Matthijs Hollemans写于2012/06/29 原文地址: http://www.raywend ...

  6. 再次讲解js中的回收机制是怎么一回事。

    在前几天的一篇闭包文章中我们简单的介绍了一下闭包,但是并没有深入的讲解,因为闭包涉及的知识点比较多,为了能够更好的理解闭包,今天讲解一下关于js中的回收机制. 在初识闭包一文中我说过js中有回收机制这 ...

  7. javascript js 内存泄露

    JavaScript 内存泄露 1.什么是闭包.以及闭包所涉及的作用域链这里就不说了. 2.JavaScript垃圾回收机制 JavaScript不需要手动地释放内存,它使用一种自动垃圾回收机制(ga ...

  8. JavaScript 中的内存泄漏

    JavaScript 中的内存泄漏 JavaScript 是一种垃圾收集式语言,这就是说,内存是根据对象的创建分配给该对象的,并会在没有对该对象的引用时由浏览器收回.JavaScript 的垃圾收集机 ...

  9. Irrlicht 3D Engine 笔记系列 之 自己定义Animator

    作者: i_dovelemon 日期: 2014 / 12 / 17 来源: CSDN 主题: Custom Animator, Referenced count 引言 在昨天的文章<Irrli ...

随机推荐

  1. kali 系统的源

    sources.list deb http://http.kali.org/kali kali-rolling main non-free contrib deb http://mirrors.ust ...

  2. 测试与 debug 心得

    测试不等同于调试,各自都有自己的概念集和方法论. Test:examine input/output pairs. 调试:定位,修改. 但如果能做到错误异常的准确定位,调试的一半以上的工作已经完成了. ...

  3. 日志报错Can't add self as subview

    #pragma mark- add 20151112 导航动画时间太短导致崩溃,重写UINavigationcontroller以下相关方法 - (id)navigationLock; ///< ...

  4. Java Math数字处理类与包装类习题

    //创建Integer类对象,并以int型返回 Integer intAb = new Integer("123"); System.out.println(intAb.intVa ...

  5. C#高效率复制对象

    高效率复制对象 1.需求 在代码中经常会遇到需要把对象复制一遍,或者把属性名相同的值复制一遍. 比如: public class Student { public int Id { get; set; ...

  6. Java 9 特性

    Java 8 发布三年多之后,已经于在2017年9月21日发布了. 你可能已经听说过 Java 9 的模块系统,但是这个新版本还有许多其它的更新. 这里有九个令人兴奋的新功能. 1. Java 平台级 ...

  7. servlet-显示器

    1.什么是监听器 监听器是实现一个特定的接口java规划,该计划的目的是还调用类方法监听器.java的awt大量使用该模式,如的能力button点击事件.当鼠标点击时,就会调用事件处理程序.又如:在j ...

  8. listview选中滑动时背景变黑

    喵的今天调这个一直以为是背景色的问题,花了好多时间 下面才是解决方法:转自:http://daijun74.iteye.com/blog/1175143 手指在ListView上下滚动时,ListVi ...

  9. PFIF网上寻人协议

    原文:http://www.csdn.net/article/2013-04-22/2814980 本文的主要内容来自Wikipedia(http://en.wikipedia.org/wiki/Pe ...

  10. 创建asp.net core 的静态网站

    这个名字听起来很怪 既然是静态网站 为什么要是asp.net core的呢? 1.在vs上面好像不能创建纯静态的网站,所以我们就想创建一个asp.net core的空网站 然后在里面使用静态的html ...