与this question类似的问题,但那里的工作答案对我没有帮助。
我的应用有一个QFrame网格。右键单击框架会将QMenu作为QFrame的子项。其中一个菜单选项创建菜单的模态QDialog子项,并使用;
显示它void ContextMenu::saveAs( )
{
QPointer<MyDlg> myDlg = new MyDlg( this );
myDlg->setModal(true);
myDlg->show();
}
单击对话框确定按钮时,MyDlg :: accept插槽被激活,它就是这样,调用close(),QDialog消失,应用程序继续运行。
单击“取消”按钮后,“对话框”消失,应用程序退出。
我尝试过实现MyDlg :: reject插槽,然后调用close()。在这种情况下,对话框不会消失,应用程序仍在运行。
我尝试通过UI编辑器附加到拒绝,它创建了MyDlg :: on_buttonBox_reject(),并且调用了close()。原始行为的结果 - 应用程序退出。
我尝试使用myDlg-&gt; exec(),而不是myDlg-&gt; show()。原始行为的结果 - 应用程序退出。
最后,我已经单独尝试了上述内容,并与this answer一致,但这对结果没有影响。
我也读过任何Qt论坛,我可以使用这些条款进行谷歌搜索,而且他们对我上面尝试的内容都有所不同。
代码不使用QApplication,它使用QMainWindow。我重写了event(),这是发生的事件列表;
2014-10-27T13:55:15.032Z Event: ParentChange
2014-10-27T13:55:15.033Z Event: ChildAdded
2014-10-27T13:55:15.033Z Event: ChildAdded
2014-10-27T13:55:15.034Z Event: StyleChange
2014-10-27T13:55:15.034Z Event: ChildAdded
2014-10-27T13:55:15.034Z Event: WindowIconChange
2014-10-27T13:55:15.034Z Event: ChildAdded
2014-10-27T13:55:15.034Z Event: ChildAdded
2014-10-27T13:55:15.034Z Event: ChildAdded
2014-10-27T13:55:15.034Z Event: ChildAdded
2014-10-27T13:55:15.034Z Event: ChildAdded
2014-10-27T13:55:15.034Z Event: ChildAdded
2014-10-27T13:55:15.035Z Event: ChildRemoved
2014-10-27T13:55:15.053Z Event: DynamicPropertyChange
2014-10-27T13:55:15.053Z Event: PaletteChange
2014-10-27T13:55:15.053Z Event: StyleChange
2014-10-27T13:55:15.053Z Event: ParentChange
2014-10-27T13:55:15.057Z Event: WinIdChange
2014-10-27T13:55:15.057Z Event: Polish
2014-10-27T13:55:15.058Z Event: PaletteChange
2014-10-27T13:55:15.058Z Event: DynamicPropertyChange
2014-10-27T13:55:15.058Z Event: PaletteChange
2014-10-27T13:55:15.058Z Event: ChildPolished
2014-10-27T13:55:15.058Z Event: ChildPolished
2014-10-27T13:55:15.058Z Event: ChildPolished
2014-10-27T13:55:15.058Z Event: Move
2014-10-27T13:55:15.058Z Event: Resize
2014-10-27T13:55:15.058Z Event: ZOrderChange
2014-10-27T13:55:15.058Z Event: Show << Show main window
2014-10-27T13:55:15.059Z Event: CursorChange
2014-10-27T13:55:15.059Z Event: ShowToParent
2014-10-27T13:55:15.059Z HApplication entering event loop...
2014-10-27T13:55:15.059Z Event: PolishRequest
2014-10-27T13:55:15.059Z Event: LayoutRequest
2014-10-27T13:55:15.059Z Event: ChildAdded
2014-10-27T13:55:15.061Z Event: WindowTitleChange
2014-10-27T13:55:15.072Z Event: ChildAdded
2014-10-27T13:55:15.072Z Event: ChildAdded
2014-10-27T13:55:15.619Z Event: UpdateLater
2014-10-27T13:55:15.619Z Event: UpdateRequest
2014-10-27T13:55:15.620Z Event: LayoutRequest
2014-10-27T13:55:15.636Z Event: Resize
2014-10-27T13:55:15.636Z Event: Move << QDialog displayed
2014-10-27T13:55:15.670Z Event: LayoutRequest
2014-10-27T13:55:15.670Z Event: UpdateRequest
2014-10-27T13:55:15.672Z Event: LayoutRequest
2014-10-27T13:55:15.672Z Event: LayoutRequest
2014-10-27T13:55:16.064Z Event: WindowTitleChange
2014-10-27T13:55:23.570Z Event: Enter
2014-10-27T13:55:23.570Z Event: HoverEnter
2014-10-27T13:55:23.570Z Event: HoverMove
2014-10-27T13:55:23.571Z Event: WindowActivate
2014-10-27T13:55:23.571Z Event: ActivationChange
2014-10-27T13:55:23.571Z Event: UpdateRequest
2014-10-27T13:55:23.578Z Event: HoverMove ...snip...
2014-10-27T13:55:24.026Z Event: HoverMove << Cancel button clicked
2014-10-27T13:55:24.450Z Event: Leave
2014-10-27T13:55:25.679Z Event: WindowBlocked
2014-10-27T13:55:34.651Z Event: WindowDeactivate
2014-10-27T13:55:34.651Z Event: ActivationChange
2014-10-27T13:55:34.654Z Event: UpdateRequest
2014-10-27T13:55:41.098Z Event: WindowUnblocked
2014-10-27T13:55:41.099Z HApplication leaving event loop...
2014-10-27T13:55:41.102Z Event: ChildRemoved
2014-10-27T13:55:41.102Z Event: ChildRemoved
2014-10-27T13:55:41.102Z Event: ChildRemoved
2014-10-27T13:55:41.102Z Event: ChildRemoved
2014-10-27T13:55:41.102Z Event: ChildRemoved
2014-10-27T13:55:41.102Z Event: ChildRemoved
2014-10-27T13:55:41.102Z Event: ChildRemoved
我很难接受下一步的尝试。有什么想法吗?