Recording a camera video to file

After we have learned how to capture a still image from our camera, let's proceed to learn how to record videos as well. First, open mainwindow.h and add the following variables:

private: 
   Ui::MainWindow *ui; 
   QCamera* camera; 
   QCameraViewfinder* viewfinder; 
   QCameraImageCapture* imageCapture; 
   QMediaRecorder* recorder; 
 
   bool connected; 
   bool recording; 

Next, open mainwindow.ui again and right-click on the Record button. Choose Go to slot... from the menu and select the clicked() option, then, click the OK button. A slot function will be created for you; then proceed to add the following code into the slot function:

void MainWindow::on_recordButton_clicked() { if (connected) { if (!recording) { recorder = new QMediaRecorder(camera); ...

Get Hands-On GUI Programming with C++ and Qt5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.