How to start camera in qt ?
-
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 -
Hi,
You should also add which version of Qt you are using.
Which brand of machine you are using, etc. -
Hi,
You should also add which version of Qt you are using.
Which brand of machine you are using, etc. -
@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!)?
-
@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!)?
-
@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.
-
@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.