环境:win10;Qt Creator 4.11.2;Qt 5.14.2
前言:qml的Loader加载窗口时有时候不想释放资源而是想要hide()窗口,这是会出现一个问题,那就是二次show时会出现重继承Loader父类窗口的层次。
现象:窗口visible=false时,窗口继承窗口层次
解决:quitOnLastWindowClosed设置为true(默认);在onClosing槽函数里用opacity=0.0替换掉 visible=false方法;让窗口一直可视也就规避了这个规律。然后设置close.accepted = false规避掉quitOnLastWindowClosed这个窗口决策。
onClosing官方说明:
closing(CloseEvent close)
This signal is emitted when the user tries to close the window.
This signal includes a close parameter. The close.accepted property is true by default so that the window is allowed to close; but you can implement an onClosing handler and set close.accepted = false if you need to do something else before the window can be closed.
The corresponding handler is onClosing.
This signal was introduced in Qt 5.1.