Hello,
Sorry for delay :)
I've try something else, this is the new code:
#include "MainWindow.h"
#include <QCameraDevice>
#include <QMediaMetaData>
#include <QCameraFormat>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
// Setup camera and video widget
camera = new QCamera(this);
videoWidget = new QVideoWidget(this);
captureSession = new QMediaCaptureSession(this);
captureSession->setCamera(camera);
captureSession->setVideoOutput(videoWidget);
// Layout
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(videoWidget);
// Combobox for video formats
formatComboBox = new QComboBox(this);
// Populate the combo box with supported formats
populateFormats();
layout->addWidget(formatComboBox);
// Current format label
currentFormatLabel = new QLabel("Current Format: ", this);
layout->addWidget(currentFormatLabel);
// Connect combobox to slot
connect(formatComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &MainWindow::onFormatChanged);
QWidget *centralWidget = new QWidget(this);
centralWidget->setLayout(layout);
setCentralWidget(centralWidget);
// Start the camera
camera->start();
}
MainWindow::~MainWindow()
{
}
void MainWindow::populateFormats()
{
const QList<QCameraFormat> formats = camera->cameraDevice().videoFormats();
for (const QCameraFormat &format : formats) {
QString formatDescription = QString("Resolution: %1x%2, Pixel Format: %3, Frame Rate: %4 fps")
.arg(format.resolution().width())
.arg(format.resolution().height())
.arg(format.pixelFormat())
.arg(format.maxFrameRate());
formatComboBox->addItem(formatDescription, QVariant::fromValue(format));
}
}
void MainWindow::onFormatChanged(int index)
{
QCameraFormat selectedFormat = formatComboBox->currentData().value<QCameraFormat>();
camera->setCameraFormat(selectedFormat);
QString formatDescription = QString("Resolution: %1x%2, Pixel Format: %3, Frame Rate: %4 fps")
.arg(selectedFormat.resolution().width())
.arg(selectedFormat.resolution().height())
.arg(selectedFormat.pixelFormat())
.arg(selectedFormat.maxFrameRate());
currentFormatLabel->setText("Current Format: " + formatDescription);
}
With this code, if I selected format with 60fps, nothing change, it's seems the video saty on 30 fps