Hello,

I would like to use the QCamera object in order to record webcam video stream. So I design my object Camera:
Qt Code:
  1. #ifndef CAMERA_H
  2. #define CAMERA_H
  3.  
  4. #include <QWidget>
  5. #include <qcamera.h>
  6. #include <qmediaplayer.h>
  7. #include <qmediarecorder.h>
  8. #include <qvideowidget.h>
  9. #include <qcameraviewfinder.h>
  10. #include <qactiongroup.h>
  11.  
  12. class Camera : public QWidget
  13. {
  14. Q_OBJECT
  15.  
  16. QCamera *camera;
  17. QMediaRecorder *recorder;
  18. QCameraViewfinder *cameraViewer;
  19.  
  20. public:
  21. explicit Camera(QWidget *parent = 0);
  22. void SetSettings();
  23. signals:
  24.  
  25. public slots:
  26. void Record();
  27.  
  28. };
  29.  
  30. #endif // CAMERA_H
To copy to clipboard, switch view to plain text mode 


Qt Code:
  1. #include "camera.h"
  2.  
  3. #include <qpushbutton.h>
  4.  
  5.  
  6. #include <iostream>
  7. #include <stdio.h>
  8. using namespace std;
  9.  
  10. Camera::Camera(QWidget *parent) :
  11. QWidget(parent)
  12. {
  13.  
  14. camera = new QCamera(0);//1
  15.  
  16. QByteArray cameraDevice;
  17.  
  18. QActionGroup *videoDevicesGroup = new QActionGroup(this);
  19. videoDevicesGroup->setExclusive(true);
  20. foreach(const QByteArray &deviceName, QCamera::availableDevices()) {
  21. QString description = camera->deviceDescription(deviceName);
  22. QAction *videoDeviceAction = new QAction(description, videoDevicesGroup);
  23. videoDeviceAction->setCheckable(true);
  24. videoDeviceAction->setData(QVariant(deviceName));
  25. cameraDevice = deviceName;
  26. break;
  27. }
  28.  
  29. delete camera;
  30. camera = new QCamera(cameraDevice,this);//1
  31.  
  32. recorder = new QMediaRecorder(camera);
  33.  
  34. cameraViewer = new QCameraViewfinder(this);
  35. camera->setViewfinder(cameraViewer);
  36.  
  37.  
  38. camera->start();//8
  39. setMinimumSize(300,300);
  40.  
  41. QPushButton *pb = new QPushButton("record",this);
  42. QPushButton *pbstop = new QPushButton("stop",this);
  43. pbstop->move(70,0);
  44. connect(pb,SIGNAL(clicked()),this,SLOT(Record()));
  45. connect(pbstop,SIGNAL(clicked()),recorder,SLOT(stop()));
  46. }
  47.  
  48.  
  49.  
  50. void Camera::SetSettings()
  51. {
  52. cameraViewer->setMinimumSize(size());
  53. cameraViewer->setMaximumSize(size());
  54. }
  55.  
  56.  
  57.  
  58. void Camera::Record()
  59. {
  60. cout << "/home/xavier/teste" << endl;
  61. recorder->setOutputLocation(QUrl("/home/xavier/teste.avi"));
  62. recorder->record();
  63. }
To copy to clipboard, switch view to plain text mode 


The probleme is when I start the recording the video I isn't display anymore in the widget. I had to stop the record to see again the video.
I run the example supply in Qt and there is the same trouble. When I start the record, the video is not display anymore(black screen or the last image from the webcam).

With this objet, are we able to display the webcam stream and record it at the same time?

Best regard.