Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Stop camera from auto starting
Forum Updated to NodeBB v4.3 + New Features

Stop camera from auto starting

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 1.4k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    Cyrille de Brebisson
    wrote on last edited by
    #1

    Hello,
    In my project, I offer a view from one of the webcam.
    However, I do not want the camera to start as soon as my app starts. I want the user to be able to select the camera from a list if he wants to (which is purely optional in the project).
    However, regardless of what I have tried, the Camera seems to always "open" the capture device and "start" streaming immediately. This is not what I want...
    What am I doing wrong?
    Here is my code:

           ComboBox {  // for selecting one of many cameras
                      model: QtMultimedia.availableCameras
                      textRole: "displayName";
                      currentIndex: -1
                      onCurrentIndexChanged: if (currentIndex!=-1) camera.deviceId= QtMultimedia.availableCameras[currentIndex].deviceId
            }
            Camera { id: camera; deviceId: ""; } // tried also: cameraState: UnloadedState
            VideoOutput {
                width: window.width; height: parent.height-y;
                source: camera
            }
    

    Thanks

    J.HilkJ raven-worxR 2 Replies Last reply
    0
    • C Cyrille de Brebisson

      Hello,
      In my project, I offer a view from one of the webcam.
      However, I do not want the camera to start as soon as my app starts. I want the user to be able to select the camera from a list if he wants to (which is purely optional in the project).
      However, regardless of what I have tried, the Camera seems to always "open" the capture device and "start" streaming immediately. This is not what I want...
      What am I doing wrong?
      Here is my code:

             ComboBox {  // for selecting one of many cameras
                        model: QtMultimedia.availableCameras
                        textRole: "displayName";
                        currentIndex: -1
                        onCurrentIndexChanged: if (currentIndex!=-1) camera.deviceId= QtMultimedia.availableCameras[currentIndex].deviceId
              }
              Camera { id: camera; deviceId: ""; } // tried also: cameraState: UnloadedState
              VideoOutput {
                  width: window.width; height: parent.height-y;
                  source: camera
              }
      

      Thanks

      J.HilkJ Online
      J.HilkJ Online
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @Cyrille-de-Brebisson
      you could try
      Camera has a start() and stop() function. So you could try

      Camera { 
          id: camera; deviceId: ""; 
          Component.onCompleted: camera.stop()
      }
      

      should work, but it's untested.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      1
      • C Cyrille de Brebisson

        Hello,
        In my project, I offer a view from one of the webcam.
        However, I do not want the camera to start as soon as my app starts. I want the user to be able to select the camera from a list if he wants to (which is purely optional in the project).
        However, regardless of what I have tried, the Camera seems to always "open" the capture device and "start" streaming immediately. This is not what I want...
        What am I doing wrong?
        Here is my code:

               ComboBox {  // for selecting one of many cameras
                          model: QtMultimedia.availableCameras
                          textRole: "displayName";
                          currentIndex: -1
                          onCurrentIndexChanged: if (currentIndex!=-1) camera.deviceId= QtMultimedia.availableCameras[currentIndex].deviceId
                }
                Camera { id: camera; deviceId: ""; } // tried also: cameraState: UnloadedState
                VideoOutput {
                    width: window.width; height: parent.height-y;
                    source: camera
                }
        

        Thanks

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        @Cyrille-de-Brebisson
        docs for Camera's deviceId property say

        If no value is provided or if set to an empty string, the system's default camera will be used.

        Try something like the following (untested though):

        Camera {
             id: camera
            deviceId: ""
            Component.onCompleted: camera.stop()
        } 
        

        or also:

        VideoOutput {
             width: window.width; height: parent.height-y;
             source: camera.deviceId.length > 0 ? camera : undefined
        }
        

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Cyrille de Brebisson
          wrote on last edited by
          #4

          Hello,

          I have tried:

          Camera {
               id: camera
              deviceId: "" // also tried deviceId: "nocamera"
              Component.onCompleted: camera.stop()
          }
          

          The result is that the camera DOES start when the app starts, and then imediately stops.
          I can see the "on light" on my camera turning on then off, the view widget does keep the last frame on, but more problematic for me, the OS does warn the user that the app wants access to the camera, which is why I would like to avoid.
          Maybe the solution is to dynamically create the camera at runtime and assign it to the VideoOutput? But I have no clue how to do that.

          Cyrille

          J.HilkJ 1 Reply Last reply
          0
          • C Cyrille de Brebisson

            Hello,

            I have tried:

            Camera {
                 id: camera
                deviceId: "" // also tried deviceId: "nocamera"
                Component.onCompleted: camera.stop()
            }
            

            The result is that the camera DOES start when the app starts, and then imediately stops.
            I can see the "on light" on my camera turning on then off, the view widget does keep the last frame on, but more problematic for me, the OS does warn the user that the app wants access to the camera, which is why I would like to avoid.
            Maybe the solution is to dynamically create the camera at runtime and assign it to the VideoOutput? But I have no clue how to do that.

            Cyrille

            J.HilkJ Online
            J.HilkJ Online
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @Cyrille-de-Brebisson
            The warning that the App is using the camera should come wether or not you actually start the camera. At least that is the way on mobile

            However you can lock into the QML component Loader, to dynamically load QML files on demand.


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved