Qt6 QML Loader doesn't work with CaptureSession
Unsolved
QML and Qt Quick
-
This has been driving me crazy for a few days now. For some reason, I cannot get
Camera
to work withLoader
. I want dynamic loading because the underlying video device can be fickle, and I'd like the UI to automatically recover from it.Here is the code:
import QtQuick 2.15 import QtMultimedia 6.6 import QtQuick.Controls 2.12 import "../../shared" Item { property string cameraDeviceName property var selectedDevice MediaDevices { id: mediaDevices } // Loader { // id: captureSessionLoader // active: true // sourceComponent: captureSessionComponent // onLoaded: { // console.log("Component loaded:", captureSessionLoader.sourceComponent == captureSessionComponent ? "Capture Session" : "Empty Component"); // } // } // Component { // id: captureSessionComponent CaptureSession { camera: Camera { id: camera cameraDevice: mediaDevices.videoInputs[0] active: true onErrorOccurred: { console.log("Camera object has some error", errorString) } } videoOutput: videoOutput } // } VideoOutput { id: videoOutput anchors.fill: parent } }
Here is what I am trying to figure out:
- If I comment out the
Loader
code, and start the UI, the camera shows up fine. - If I uncomment the
Loader
code, and start the UI, nothing shows up on the screen. - I tried replace
CaptureSession
with a simple rectangle, it would show up on the screen fine.
So apparently something is wrong with
Loader
working withCaptureSession
, but I cannot figure out what. I do not see any errors being printed out on the console. And I do seeComponent loaded
every time I start the UI, so it's not an issue with not loader not loading.Thanks for any comments!
- If I comment out the