Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    VideoOutput and Camera never ready

    QML and Qt Quick
    1
    1
    786
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mkrus last edited by

      I'm trying to use the Camera and VideoOutput QML components to implement image capture.
      In the app, the user will go through a number of steps and at some point will hit a
      button at which point I want to activate the camera, show the video output, present
      a snap button to let the user a capture

      When I put a VideoOutput element in my main QML and assign it the camera,
      the app will immediately prompt the user to decide if he wants to let the app access the
      camera. This happens when the VideoOuput.source is bound to the camera. If done in the
      main, this happens at startup time, long before the user would well get to the point

      So I tried:

      • delaying the binding of VideoOutput.source to camera to a the point when the user
        presses a button
      • or using a Loader to load the VideoOutput and the snap UI when a button is pressed.

      My problem is that when things are setup in either of these ways,
      camera.imageCapture.ready never becomes true and calling capture() prints out
      'QCameraImageCapture error: "Camera not ready"'

      Here is a sample QML below.

      Any ideas?

      ===============================
      @import QtQuick 2.3
      import QtQuick.Window 2.2
      import QtMultimedia 5.2

      Window {
      id:root
      visible: true
      width: 1024
      height: 768

      Rectangle {
          width: 200
          height: 30
          anchors.centerIn: parent
          color: "lightblue"
      
          Text {
              anchors.fill: parent
              text: "Tap to Take a Picture"
              horizontalAlignment: Text.AlignHCenter
              verticalAlignment: Text.AlignVCenter
          }
      
          MouseArea {
              anchors.fill: parent
              onClicked: {
                  viewfinderLoader.startCapture()
              }
          }
      }
      
      Camera {
          id: camera
          captureMode: Camera.CaptureViewfinder
      
          imageCapture {
              onImageCaptured: {
                  root.state = "PhotoPreview"
                  imagePreview.source = preview
              }
          }
      }
      
      Component {
          id: viewFinderComponent
      
          Rectangle {
              id: viewfinder
              anchors.fill: parent
              color: "white"
      
              property var camera
              property bool cameraReady: camera && camera.imageCapture.ready
              onCameraChanged: {
                  if(camera) {
                      videoOut.source = camera
                  }
              }
      
              signal cancelled()
              function onCameraReadyChanged() {
                  console.log("onCameraReadyChanged", cameraReady)
              }
      
              VideoOutput {
                  id: videoOut
                  anchors.fill: parent
                  autoOrientation: true
              }
      
              Rectangle {
                  id: snapButton
      

      // enabled: viewfinder.cameraReady
      color: "#eeeeee"
      width: 88
      height: width
      radius: 44
      anchors.horizontalCenter: parent.horizontalCenter
      anchors.bottom: parent.bottom
      anchors.bottomMargin: 5
      opacity: enabled ? 1 : .5

                  Rectangle {
                      color: "red"
                      anchors.fill: parent
                      anchors.margins: 8
                      radius: width / 2
                  }
      
                  MouseArea {
                      anchors.fill: parent
                      onClicked: {
                          camera.imageCapture.capture()
                      }
                  }
              }
      
              Text {
                  text: "X"
                  font.pixelSize: 42
                  horizontalAlignment: Text.AlignHCenter;
                  verticalAlignment: Text.AlignVCenter;
                  anchors.right: parent.right
                  anchors.top: parent.top
                  anchors.margins: 5
                  width: 44
                  height: 44
                  color: "black"
      
                  MouseArea {
                      anchors.fill: parent
                      onClicked: viewfinder.cancelled()
                  }
              }
      
              Behavior on opacity {
                  NumberAnimation {
                      duration: 200
                  }
              }
          }
      }
      
      Loader {
          id: viewfinderLoader
          anchors.fill: parent
      
          onLoaded: {
              camera.captureMode = Camera.CaptureStillImage
              camera.start()
              item.camera = camera
              item.cancelled.connect(onCancelled)
          }
      
          function startCapture() {
              sourceComponent = viewFinderComponent
          }
      
          function stopCapture() {
          }
      
          function onCancelled() {
              sourceComponent = undefined
          }
      }
      

      }
      @

      1 Reply Last reply Reply Quote 0
      • First post
        Last post