Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to start camera in qt ?
Forum Updated to NodeBB v4.3 + New Features

How to start camera in qt ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 364 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.
  • G Offline
    G Offline
    Golubev
    wrote on last edited by Golubev
    #1

    I started making a camera and ran into the problem that I can't display an image when I use the desktop application on win 11. Even the Camera example doesn't work. maybe you need some permissions for win 11?

    CaptureSession {
                id: captureSession
                videoOutput: videoOutput
                
                camera: Camera {
                    id: camera
                }
                imageCapture: ImageCapture {
                    id: imageCapture
                    onErrorOccurred: function(requestId, error, message) {
                        console.log("Error occurred", requestId, error, message);
                    }
                    onImageCaptured: function(requestId, previewImage) {
                        console.log("Image captured", requestId, previewImage);
                    }
                    onImageSaved: function(requestId, path) {
                        console.log("Image saved", requestId, path);
                        TaskManager.attachPhotoToTask(taskId,path)
                        
                        loader.push("TaskEditDialogImages.qml",{taskId = taskId})
                    }
                }
                
            }
            
            VideoOutput {
                id: videoOutput
                anchors {
                    top: controlsRow.bottom
                    bottom: parent.bottom
                    left: parent.left
                    right: parent.right
                    margins: 10
                }
            }
    

    Everything works on android, although it doesn't show the picture on some devices. Permissions in main.cpp I added. I use the Cmake file. I even added a check.

    QCameraPermission cameraPermission;
        qApp->requestPermission(cameraPermission, [&](const QPermission &permission) {
            if (permission.status() == Qt::PermissionStatus::Granted) {
                qDebug() << "Camera permission granted";
            } else {
                qWarning() << "Camera permission denied!";
            }
     } );
    
    

    when I click on the button, it returns an error : qml: Error occurred -1 1 Could not capture in stopped state

    Button {
                    id: captureButton
                    implicitWidth: 50
                    implicitHeight: 50
                    radius: 30
                    onClicked: {
                        captureSession.imageCapture.captureToFile(CameraManager.getPath());
                    }
                    Image {
                        id: photoIcon
                        source: "photoIcon.png"
                        anchors.fill: parent
                        anchors.centerIn: photoIcon
                    }
                }
    

    also use :

    property bool isActive: StackView.view ? StackView.view.currentItem === cameraPage : false
        onIsActiveChanged: {
            console.log("Camera page active:", isActive)
            if (isActive) {
                camera.start()
            } else {
                camera.stop()
            }
        }
    

    before opening, he writes that the camera starts and on the laptop itself it is visible with a light bulb.
    please help me solve the problem

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You should also add which version of Qt you are using.
      Which brand of machine you are using, etc.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      G 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        You should also add which version of Qt you are using.
        Which brand of machine you are using, etc.

        G Offline
        G Offline
        Golubev
        wrote on last edited by
        #3

        @SGaist use Based on Qt 6.8.2 (MSVC 2022, x86_64) .Laptop Hp proBook 450 G9

        jsulmJ 1 Reply Last reply
        0
        • G Golubev

          @SGaist use Based on Qt 6.8.2 (MSVC 2022, x86_64) .Laptop Hp proBook 450 G9

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Golubev said in How to start camera in qt ?:

          Based on Qt 6.8.2 (MSVC 2022, x86_64)

          Do you mean QtCreator is based on this Qt version or is this the Qt version you're using (this is not the same!)?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          G 1 Reply Last reply
          0
          • jsulmJ jsulm

            @Golubev said in How to start camera in qt ?:

            Based on Qt 6.8.2 (MSVC 2022, x86_64)

            Do you mean QtCreator is based on this Qt version or is this the Qt version you're using (this is not the same!)?

            G Offline
            G Offline
            Golubev
            wrote on last edited by
            #5

            @jsulm (af0bfb0e-2942-4ae0-9ba9-08654be58cdc-image.png image)

            I don't even know where to look, but it looks like it

            (b576be25-5279-4273-98bf-0dce41ac6d41-image.png image)

            jsulmJ 1 Reply Last reply
            0
            • G Golubev

              @jsulm (af0bfb0e-2942-4ae0-9ba9-08654be58cdc-image.png image)

              I don't even know where to look, but it looks like it

              (b576be25-5279-4273-98bf-0dce41ac6d41-image.png image)

              jsulmJ Online
              jsulmJ Online
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Golubev said in How to start camera in qt ?:

              I don't even know where to look

              You should know what Qt version you installed. If you don't know when go to the Kit configuration in QtCreator and check what Qt version is set there.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              G 1 Reply Last reply
              0
              • jsulmJ jsulm

                @Golubev said in How to start camera in qt ?:

                I don't even know where to look

                You should know what Qt version you installed. If you don't know when go to the Kit configuration in QtCreator and check what Qt version is set there.

                G Offline
                G Offline
                Golubev
                wrote on last edited by
                #7

                @jsulm This one ? (a0a93547-b7b1-41c2-9fd5-a74728bf8eab-image.png image url)

                I remembered I was installing 6.7.3

                jsulmJ 1 Reply Last reply
                0
                • G Golubev

                  @jsulm This one ? (a0a93547-b7b1-41c2-9fd5-a74728bf8eab-image.png image url)

                  I remembered I was installing 6.7.3

                  jsulmJ Online
                  jsulmJ Online
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Golubev Can you try with the latest Qt6 version?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  G 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @Golubev Can you try with the latest Qt6 version?

                    G Offline
                    G Offline
                    Golubev
                    wrote on last edited by
                    #9

                    @jsulm Also with Qt 6.9.0
                    (228b84f8-fec9-43e9-bb09-c4f667d53cb7-image.png image )

                    as u see its a win 11 problem becase i open Qt project example "declarative-camera". But laptop sad me that camera is started.

                    1 Reply Last reply
                    0

                    • Login

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