【问题标题】:qml CaptureSession freezes app on Androidqml CaptureSession 冻结 Android 上的应用程序
【发布时间】:2023-01-30 12:22:07
【问题描述】:

我在 Qt6.4 上使用 CaptureSession 时有一个错误,如果我在动态组件中使用它,当我销毁它时,应用程序会冻结,我必须杀死它。 当我为桌面编译时,这个问题不存在。 我在 Android 11 & 13 上试过,结果是一样的。

当仅使用 VideoOuput 和 Camera 时,它也可以完美地与 Qt5 一起工作。

我使用 Loader 编写了一个最小示例,它创建了冻结。如果有人有修复它的想法:

import QtQuick 6.4
import QtQuick.Window 6.4
import QtQuick.Controls 6.4
import QtMultimedia

ApplicationWindow
{
id: window
visible: true
width: Screen.desktopAvailableWidth
height: Screen.desktopAvailableHeight

Loader {
    id: loader
    anchors.fill: parent
    active: activeBtn.checked
    sourceComponent: Component {
        Item {
            id: item

            Camera {
                id: camera
                active: true
                focusMode: Camera.FocusModeAutoNear
            }

            CaptureSession {
                camera: camera
                videoOutput: videoOutput
            }

            VideoOutput {
                id: videoOutput
                anchors.fill: parent

                fillMode: VideoOutput.Stretch
            }
        }
    }
}


Button {
    id : activeBtn
    text: "Active CAM"
    checkable: true
    anchors {
        right: parent.right
        bottom: parent.bottom
    }
}
}

一旦我卸载组件,应用程序就会冻结,因此当 CaptureSession 被销毁时。

【问题讨论】:

    标签: android camera qml freeze qt6


    【解决方案1】:

    我会确保在销毁Component之前停止Camera。我们可以保留您的原始属性以启动相机,即

        property bool cameraActive: false
        Loader {
            id: loader
            anchors.fill: parent
            active: activeBtn.checked || cameraActive
    

    因此,一旦 Button 被选中,就会创建组件,但是,在 Component 的初始化期间,我们更改了 cameraActive = true;,以防止取消选中相同的 Button 以销毁组件。相反,我们使用该事件来停止Camera和camera.stop()。一旦我们知道 Camera 已停止为 camera.active === false,我们就会更改 cameraActive = false,这应该会恢复对你的 Component 的销毁。

    import QtQuick 6.4
    import QtQuick.Window 6.4
    import QtQuick.Controls 6.4
    import QtMultimedia
    
    ApplicationWindow
    {
        id: window
        visible: true
        width: Screen.desktopAvailableWidth
        height: Screen.desktopAvailableHeight
        property bool cameraActive: false
    
        Loader {
            id: loader
            anchors.fill: parent
            active: activeBtn.checked || cameraActive
            sourceComponent: Component {
                Item {
                    id: item
                    
                    Camera {
                        id: camera
                        active: true
                        focusMode: Camera.FocusModeAutoNear
                        onActiveChanged: cameraActive = active
                    }
                    
                    CaptureSession {
                        camera: camera
                        videoOutput: videoOutput
                    }
                    
                    VideoOutput {
                        id: videoOutput
                        anchors.fill: parent
                        
                        fillMode: VideoOutput.Stretch
                    }
    
                    Connections {
                        target: activeBtn
                        function onCheckedChanged() {
                            if (!activeBtn.checked && camera.active) {
                                camera.stop();
                            }
                        }
                    }
    
                    Component.onCompleted: {
                        cameraActive = true;
                    }
                }
            }
        }
        
        
        Button {
            id : activeBtn
            text: "Active CAM"
            checkable: true
            anchors {
                right: parent.right
                bottom: parent.bottom
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-01-15
      • 1970-01-01
      • 2016-07-02
      • 2021-09-24
      • 2017-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多