当使用 QApplication 而不是 QGuiApplication 时,MessageDialog 的 accepted、rejected 信号会触发两次,一种替代方案是使用 Qt.labs.platform 模块的 MessageDialog。
单例实现使用 static 对象,很明显是不能对这个单例指针 delete 的
- AppManager *AppManager::getInstance()
- {
- static AppManager instance;
- return &instance;
- }
注册单例时可以设置为 QQmlEngine::CppOwnership,避免被 QML 引擎释放
- qmlRegisterSingletonType<AppManager>(
- "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: 640
- height: 480
- visible: true
- title: qsTr("Main")
-
- Button {
- text: "open"
- onClicked: w2.show()
- }
-
- Window {
- id: w2
- width: 300
- height: 200
- title: qsTr("Sub")
- Button {
- anchors.centerIn: parent
- text: 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 信号来获取当前媒体的总时长。
暂时没看到相应的接口,所以我先设置一个空的路径,再把原来的路径设置回去。