In my project I capture photo to buffer using QCameraImageCapture::CaptureToBuffer
. But it also saves images to the file. Since I am planning to capture images continuously I want to prevent it from saving images to the file. Here is my code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
scene = new QGraphicsScene(this);
ui->graphicsView->setScene(scene);
cam = new QCamera;
cam->setCaptureMode(QCamera::CaptureStillImage);
viewfinder = new QCameraViewfinder;
viewfinder->show();
QCameraImageCapture *cap = new QCameraImageCapture(cam);
cap->setCaptureDestination(QCameraImageCapture::CaptureToBuffer);
cam->setViewfinder(viewfinder);
QObject::connect(cap, &QCameraImageCapture::imageCaptured, [=] (int id, QImage img) {
QByteArray buf;
QBuffer buffer(&buf);
buffer.open(QIODevice::WriteOnly);
img.save(&buffer, "BMP");
});
QObject::connect(cap, &QCameraImageCapture::readyForCaptureChanged, [=] (bool state) {
if(state == true) {
cam->searchAndLock();
cap->capture();
cam->unlock();
}
});
cam->start();
}
It depends on the QCamera backend. I believe that bug you are describing exists in GStreamer camerabin plugin. When you look to https://code.qt.io/cgit/qt/qtmultimedia.git/tree/src/plugins/gstreamer/camerabin/camerabinsession.cpp?h=5.15#n587
m_imageFileName
is setup independently on capture destination. File is saved by this filter then https://code.qt.io/cgit/qt/qtmultimedia.git/tree/src/plugins/gstreamer/mediacapture/qgstreamercapturesession.cpp?h=5.15#n404edit: this bug seems to be fixed in Qt 5.15