diff --git a/src/core/barcodedecoder.cpp b/src/core/barcodedecoder.cpp index 9801c08164..9a3a4e96d3 100644 --- a/src/core/barcodedecoder.cpp +++ b/src/core/barcodedecoder.cpp @@ -114,7 +114,7 @@ void BarcodeDecoder::decodeImage( const QImage &image ) #if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) QVideoSink *BarcodeDecoder::videoSink() const { - return mVideoSink; + return mVideoSink.get(); } void BarcodeDecoder::setVideoSink( QVideoSink *sink ) diff --git a/src/core/barcodedecoder.h b/src/core/barcodedecoder.h index 690bf32c7d..1befe0b283 100644 --- a/src/core/barcodedecoder.h +++ b/src/core/barcodedecoder.h @@ -21,6 +21,7 @@ #include #include #if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) +#include #include #endif @@ -60,7 +61,7 @@ class BarcodeDecoder : public QObject #if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) QThread *mDecodingThread = nullptr; - QVideoSink *mVideoSink = nullptr; + QPointer mVideoSink; signals: void videoSinkChanged(); diff --git a/src/qml/imports/QFieldControls/+Qt6/BarcodeReader.qml b/src/qml/imports/QFieldControls/+Qt6/BarcodeReader.qml index 6b52b262ef..8d2418639f 100644 --- a/src/qml/imports/QFieldControls/+Qt6/BarcodeReader.qml +++ b/src/qml/imports/QFieldControls/+Qt6/BarcodeReader.qml @@ -35,7 +35,6 @@ Popup { BarcodeDecoder { id: barcodeDecoder - videoSink: videoOutput.videoSink onDecodedStringChanged: { if (decodedString !== '') { @@ -44,27 +43,6 @@ Popup { } } - Loader { - id: cameraLoader - sourceComponent: cameraComponent - active: barcodeReader.visible - - onLoaded: { - item.videoOutput = videoOutput - } - } - - Component { - id: cameraComponent - - CaptureSession { - camera: Camera { - active: barcodeReader.visible - flashMode: Camera.FlashOff - } - } - } - Page { width: parent.width height: parent.height @@ -119,11 +97,40 @@ Popup { radius: 10 clip: true - VideoOutput { - id: videoOutput + Loader { + id: cameraLoader + sourceComponent: cameraComponent + active: barcodeReader.visible anchors.fill: parent - anchors.margins: 6 - fillMode: VideoOutput.PreserveAspectCrop + + onLoaded: { + barcodeDecoder.videoSink = item.sink + } + } + + Component { + id: cameraComponent + + Item { + property alias camera: captureSession.camera + property alias sink: videoOutput.videoSink + + CaptureSession { + id: captureSession + camera: Camera { + active: true + flashMode: Camera.FlashOff + } + videoOutput: videoOutput + } + + VideoOutput { + id: videoOutput + anchors.fill: parent + anchors.margins: 6 + fillMode: VideoOutput.PreserveAspectCrop + } + } } Rectangle {