Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

Pass Camera preview from QML to C++

$
0
0
Hey, I got a problem with passing Camera preview from QML to C++, I need to process it there. Here is my code, anyone knows what I am doing wrong? Test.cpp #include "test.h"   Test::Test(QObject *rootObject, QObject *parent) : QObject(parent) {     QObject *camera = rootObject->findChild<QObject *>(QString("camera"));     setCamera(camera); }   void Test::processPreview(int, const QImage& image) {     qDebug() << "PROCESS IMAGE" << image; }   void Test::setCamera(QObject *cameraObject) {     QVariant cameraVariant = cameraObject->property("mediaObject");     QCamera *camera = qvariant_cast<QCamera*>(cameraVariant);     QCameraImageCapture *imageCapture = new QCameraImageCapture(camera);     connect(imageCapture, SIGNAL(imageCaptured(int, const QImage&)),         this, SLOT(processPreview(int, const QImage&))); }   void Test::setCamera2(QObject *cameraObject) {     QVariant cameraVariant = cameraObject->property("mediaObject");     QCamera *camera = qvariant_cast<QCamera*>(cameraVariant);     QMediaService *service = camera->service();     QMediaControl *control = service->requestControl(QCameraImageCaptureControl_iid);     QCameraImageCaptureControl *captureControl = qobject_cast<QCameraImageCaptureControl*>(control);     connect(captureControl, SIGNAL(imageCaptured(int, const QImage&)),         this, SLOT(processPreview(int, const QImage&))); }   void Test::imageCapture(QString url) {     qDebug() << url; }   Test::~Test() {   } and main.qml import QtQuick 2.4 import QtQuick.Controls 1.3 import QtQuick.Window 2.2 import QtQuick.Dialogs 1.2 import QtMultimedia 5.4   ApplicationWindow {     title: qsTr("Hello World")     width: 640     height: 480     visible: true       Item {         anchors.fill: parent           Camera {             objectName: "camera"             id: camera                   imageProcessing.whiteBalanceMode: CameraImageProcessing.WhiteBalanceFlash               exposure {                 exposureCompensation: -1.0                 exposureMode: Camera.ExposurePortrait             }               flash.mode: Camera.FlashRedEyeReduction               imageCapture {                 onImageCaptured: {                     photoPreview.source = preview  // Show the preview in an Image                 }             }         }           VideoOutput {             source: camera             anchors.fill: parent             focus : visible // to receive focus and capture key events when visible         }           Image {             id: photoPreview             onSourceChanged: imageChanged(source)         }     } } I tried both setCamera and setCamera2 but they doesnt work. I can see the preview on Android tablet, which I am using for testing. Thanks in advance

Viewing all articles
Browse latest Browse all 4972

Latest Images

Trending Articles



Latest Images