[QTBUG-94126] If inherit QApplication, the MessageDialog accepted signal is emitted twice. - Qt Bug Tracker
当使用 QApplication 而不是 QGuiApplication 时,MessageDialog 的 accepted、rejected 信号会触发两次,一种替代方案是使用 Qt.labs.platform 模块的 MessageDialog。
单例实现使用 static 对象,很明显是不能对这个单例指针 delete 的
AppManager *AppManager::getInstance()
{static AppManager instance;return &instance;
}
注册单例时可以设置为 QQmlEngine::CppOwnership,避免被 QML 引擎释放
qmlRegisterSingletonType("Handy.Manager", 1, 0,"AppManager", [](QQmlEngine* qmlEngine, QJSEngine*){qmlEngine->setObjectOwnership(AppManager::getInstance(), QQmlEngine::CppOwnership);return AppManager::getInstance();});
设置环境变量启用 QSG_RHI
qputenv("QSG_RHI", "1");
此时如果有 Window 类型的弹框,直接调用 close 或者点标题栏关闭,多点几次可能会触发异常,如果是 hide 似乎就能正常工作
Window {width: 640height: 480visible: truetitle: qsTr("Main")Button {text: "open"onClicked: w2.show()}Window {id: w2width: 300height: 200title: qsTr("Sub")Button {anchors.centerIn: parenttext: qsTr("hide")onClicked: w2.hide()}}
}
异常发生时会有提示,然后这个子窗口的内容就没法显示出来的,成了一个空白的窗口
Failed to resize D3D11 swapchain: Error 0x80070005: ????????
Failed to build or resize swapchain
Failed to present: Error 0x887a0001: ??ó???????????Ч????á???????????????????????????
???? D3D ????????????????????????????
Failed to end frame
根据文档描述,Qt5 QMediaPlayer 的 duration 需要连接 durationChanged 信号来获取当前媒体的总时长。
下一篇:曲柄压力机的离合器和制动系统设计