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. QCameraImageCapture resource error on imageSave

QCameraImageCapture resource error on imageSave

Scheduled Pinned Locked Moved Unsolved General and Desktop
qcameraqmultimediaqcameraimagecap
2 Posts 2 Posters 1.4k Views
  • 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.
  • SolaVitaeS Offline
    SolaVitaeS Offline
    SolaVitae
    wrote on last edited by
    #1

    I'm currently trying to capture a still image with a QCamera Widget, but whenever i try to run the capture() function of QCameraImageCapture, it errors and gives me a QCameraImageCapture::ResourceError "Could not save image to file."

    Ive tried my hardest to copy directly from the QCamera example from QT, whilst cutting out the video recording part of it as i only need still images.

    This is my widget's constructor

    	connect(saveImageButton, SIGNAL(pressed()), this, SLOT(saveImagePressed()));
    	
    
    	if (!checkCameraAvailability()) close();
    
    	QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
    
    	availableCameras->setFocusPolicy(Qt::NoFocus);
    
    	QPalette p = palette();
    	p.setBrush(QPalette::Highlight, QBrush(Qt::white));
    	p.setBrush(QPalette::HighlightedText, QBrush(Qt::black));
    	availableCameras->setPalette(p);
    
    	foreach(const QCameraInfo &ci, cameras) {
    		QCheckBox *cam = new QCheckBox(ci.description());
    		QListWidgetItem *lwi = new QListWidgetItem();
    		availableCameras->addItem(lwi);
    		availableCameras->setItemWidget(lwi, cam);
    	}
    
    	m_camera.reset(new QCamera(QCameraInfo::availableCameras()[0]));
    	
    	connect(m_camera.data(), QOverload<QCamera::Error>::of(&QCamera::error), this, &WebCamDialog::displayCameraError);
    	
    	m_camera->setViewfinder(ui->viewFinder);
    	m_camera->viewfinderSettings().setResolution(QSize(400, 400));
    	qDebug() << m_camera->viewfinderSettings().resolution();
    
    	m_camera->setCaptureMode(QCamera::CaptureStillImage);
    
    	m_imageCapture.reset(new QCameraImageCapture(m_camera.data()));
    
    	connect(m_imageCapture.data(), QOverload<int, QCameraImageCapture::Error, const QString &>::of(&QCameraImageCapture::error),
    		this, &WebCamDialog::displayCaptureError);
    
    	connect(m_imageCapture.data(), SIGNAL(imageCaptured(int, const QImage)), this, SLOT(imageCaptured(int, const QImage)));
    	connect(m_imageCapture.data(), SIGNAL(imageSaved(int, const QString)), this, SLOT(imageSaved(int, const QString)));
    
    
    	m_camera->start();
    

    this is my capture function when a button is pressed

    void WebCamDialog::saveImagePressed() {
    	qDebug() << m_imageCapture->isReadyForCapture();
    	qDebug() << m_camera->lockStatus() << m_imageCapture->isReadyForCapture();
    	m_imageCapture->capture();
    }
    

    the above qDebug returns true, QCamera::Unlocked, true

    these are my imageSaved, imageCaptured, and error functions

    void WebCamDialog::imageCaptured(int id, const QImage &i) {
    	QLabel *im = new QLabel();
    	im->setPixmap(QPixmap::fromImage(i));
    	im->show();
    
    }
    
    void WebCamDialog::imageSaved(int id, const QString &s) {
    	qDebug() << s;
    }
    
    void WebCamDialog::displayCaptureError(int id, QCameraImageCapture::Error error, const QString &errorString) {
    	Q_UNUSED(id);
    	qDebug() << error;
    	qDebug() << tr("Image Capture Error") << errorString;
    }
    

    imageCaptured displays the captured image correctly, imageSaved is never reached. I only have one camera available so i've ommited the actual selecting of a camera, and just made it default to the only camera i have

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Try adding m_imageCapture.setCaptureDestination(QCameraImageCapture::CaptureToFile);.

      P.S.

      QCheckBox *cam = new QCheckBox(ci.description());
      vailableCameras->setItemWidget(lwi, cam);
      

      Hurts my feelings. See https://forum.qt.io/post/486329 it applies also to QListWidgetItem with the only difference that you don't, obviously, specify a column

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      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