Solved Qml Camera Image Capture
-
HI.
I tired to modify this example
I have add at My root ApplicationWindow but when to start simulator the app open but after died
this is my main.qml:
import QtQuick.Controls 1.4 import QtQuick 2.0 import QtMultimedia 5.4 ApplicationWindow{ id:window color: "#ec4e4e" title: "ProvaZxing" visible: true Rectangle { id : cameraUI color: "black" anchors.fill: parent state: "PhotoCapture" states: [ State { name: "PhotoCapture" StateChangeScript { script: { camera.captureMode = Camera.CaptureStillImage camera.start() } } }, State { name: "PhotoPreview" }, State { name: "VideoCapture" StateChangeScript { script: { camera.captureMode = Camera.CaptureVideo camera.start() } } }, State { name: "VideoPreview" StateChangeScript { script: { camera.stop() } } } ] Camera { id: camera captureMode: Camera.CaptureStillImage imageCapture { onImageCaptured: { photoPreview.source = preview stillControls.previewAvailable = true cameraUI.state = "PhotoPreview" } } videoRecorder { resolution: "640x480" frameRate: 30 } } PhotoPreview { id : photoPreview anchors.fill : parent onClosed: cameraUI.state = "PhotoCapture" visible: cameraUI.state == "PhotoPreview" focus: visible } VideoPreview { id : videoPreview anchors.fill : parent onClosed: cameraUI.state = "VideoCapture" visible: cameraUI.state == "VideoPreview" focus: visible //don't load recorded video if preview is invisible source: visible ? camera.videoRecorder.actualLocation : "" } VideoOutput { id: viewfinder visible: cameraUI.state == "PhotoCapture" || cameraUI.state == "VideoCapture" x: 0 y: 0 width: parent.width - stillControls.buttonsPanelWidth height: parent.height source: camera autoOrientation: true } PhotoCaptureControls { id: stillControls anchors.fill: parent camera: camera visible: cameraUI.state == "PhotoCapture" onPreviewSelected: cameraUI.state = "PhotoPreview" onVideoModeSelected: cameraUI.state = "VideoCapture" } VideoCaptureControls { id: videoControls anchors.fill: parent camera: camera visible: cameraUI.state == "VideoCapture" onPreviewSelected: cameraUI.state = "VideoPreview" onPhotoModeSelected: cameraUI.state = "PhotoCapture" } } } /*##^## Designer { D{i:0;autoSize:true;height:480;width:640} } ##^##*/
my pro file
QT += quick CONFIG += c++11 # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Refer to the documentation for the # deprecated API to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ main.cpp RESOURCES += qml.qrc # Additional import path used to resolve QML modules in Qt Creator's code model QML_IMPORT_PATH = # Additional import path used to resolve QML modules just for Qt Quick Designer QML_DESIGNER_IMPORT_PATH = # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target DISTFILES += \ CameraButton.qml \ CameraListButton.qml \ CameraListPopup.qml \ CameraPropertyButton.qml \ CameraPropertyPopup.qml \ FocusButton.qml \ PhotoCaptureControls.qml \ PhotoPreview.qml \ Popup.qml \ VideoCaptureControls.qml \ VideoPreview.qml \ ZoomControl.qml \ declarative-camera.qml \ images/camera_auto_mode.png \ images/camera_camera_setting.png \ images/camera_flash_auto.png \ images/camera_flash_fill.png \ images/camera_flash_off.png \ images/camera_flash_redeye.png \ images/camera_white_balance_cloudy.png \ images/camera_white_balance_flourescent.png \ images/camera_white_balance_incandescent.png \ images/camera_white_balance_sunny.png \ images/toolbutton.png \ images/toolbutton.sci
-
@Nio74
since this is in mobile and embedded, I'm guessing this is for an android or iOS device?You'll have to add and request camera permissions before starting your camera or the application will simply crash.
-
@J.Hilk said in Qml Camera Image Capture:
@Nio74
since this is in mobile and embedded, I'm guessing this is for an android or iOS device?You'll have to add and request camera permissions before starting your camera or the application will simply crash.
I have put the camera permission but not work this is project
-
@Nio74 I suggest you to include all needed modules
In your PRO file, add
QT += core qml quick multimedia
-
I added but it not work, the only strange thing and when i go into the design module it tells me about windows multimedia is not loaded, but it also tells me in the original project. Has anyone tried on his machine to see if it works? Thanks
-
@Nio74 What is your Target OS: Linux, Windows, Android, IOS??
-
Android ArmV7
-
@Nio74 clean your build and rerun make after changing your *.pro file.
also newer Android SDK's requiere runtime permission checks. Simply adding them to the manifest is no longer enough.
I don't know if QML does that automatically, but I still ask from cpp side each start of the app via
https://doc.qt.io/qt-5/qtandroid.html#checkPermission
and
https://doc.qt.io/qt-5/qtandroid.html#requestPermissions -
I have found the problem, an external folder called QML had been created, instead importing them into the folder that I highlighted as correct now works.