PDA

View Full Version : How to get QCamera to work?



feraudyh
31st January 2014, 21:25
I want to use QCamera, but the page on QCamera does not say how I must change my project file to use it.
I've got QT += multimedia multimediawidgets
but this appears to be insufficient.
It seems to me that for every class the doc hould mention this kind of detail.

Added after 18 minutes:

It seems now that i just had to wait several minutes before QtCreator woke up to the fact that I had added
QT += multimedia multimediawidgets
to the project file
and now "magically"
#include <QCameraViewfinder>
#include <QCamera>
are no longer underlined in green.

problem solved, but my remark about the doc still holds.

ChrisW67
1st February 2014, 01:14
Get into the habit of running qmake after you modify a PRO file.

The modification required to the PRO file is documented at the module level.
Qt Multimedia (http://qt-project.org/doc/qt-5.0/qtmultimedia/qtmultimedia-index.html)

feraudyh
12th February 2014, 19:12
Hi,
I've used QCamera on Windows, now I'd like to port my stuff to Linux.
I downloaded Qt 5.2.1 on XUbuntu, and I've got a message saying QCamera cannot be found (when I try to #include <QCamera>)
Does anyone know if QCamera is planned, or do I just need to download some extensions?

feraudyh
12th February 2014, 21:17
It seems that the QtCreator 3.0.1 + Qt 5.2.1 does not support QCamera on Xubuntu.
Any workarounds? Any plans for it to be released in the near future?
Furthermore the MultimediaWidgets module is rejected by qmake.

stampede
12th February 2014, 22:11
QCamera worked for me on Linux Mint (latest release) with gstreamer backend - I can't remember exactly, but I think I had to install the "bad" plugins set (gst-plugins-bad) and build the QCamera gstreamer plugin from source ("qtmultimedia\src\plugins\gstreamer\camerabin"). I didn't care about the audio, so I can't really help you with that.
Anyway, every camera I tested supported only one basic capture mode (typically 800x600@20 fps), without the possibility to change it, even if hardware supports much bigger resolutions / framerates.

pratik.manvar
23rd June 2016, 15:03
Hi,

I am having problem in recording video using QMediaRecorder and QCamera classes.
My application crashes with segmentation fault when trying to start camera ("camera->start" in code).

Below is code, i have written. Please guide me out here, if have i am missing something. Thanks in advance.


/************************************************** ********************/
QMediaRecorder *recorder;
QCamera *camera;
QCameraViewfinder *viewfinder;

QCameraInfo cameraInfo(camera);
QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
foreach (cameraInfo, cameras)
qDebug() << cameraInfo.deviceName();

camera = new QCamera(cameraInfo);

viewfinder = new QCameraViewfinder();
camera->setViewfinder(viewfinder);
setCentralWidget(viewfinder);
viewfinder->show();

if(true == isCaptureModeSupported(QCamera::CaptureVideo)
{
camera->setCaptureMode(QCamera::CaptureVideo);
}

recorder = new QMediaRecorder(camera);
camera->start();

recorder->setOutputLocation(QUrl::fromLocalFile("record.mp4"));
recorder->record();

/************************************************** ********************/

d_stranz
23rd June 2016, 16:21
Where is this code? In a MainWindow constructor? In the constructor, the MainWindow (and all of its children) are not yet visible and do not have valid sizes. This could be part of the problem - that you are telling the camera to start displaying on a viewfinder window that has not been fully initialized. You are also starting the camera before you have told the recorder where to write its output. Calling "viewfinder->show()" in the constructor is a waste of time. It will be shown when the MainWindow is shown, and that does not happen until the showEvent().

I would suggest that you implement a showEvent() handler for the MainWindow and move the camera->start() call there. All of the other setup can probably remain where it is. You will need to make the camera instance a member variable of the MainWindow class if it is not already.

And use CODE tags when posting source code.

pratik.manvar
24th June 2016, 10:59
Hello d_stranz,

Thanks for your reply.

The code is not in constructor, there is a push-button to start recording.

Here with i have attached files of my code. Thanks for the knowledge for pasting source code:).

bilal mohamed
24th June 2020, 20:22
can you please add the ui.mainwindow file

d_stranz
24th June 2020, 22:05
You don't really need the specific file for this project. All the poster did was to make the QCameraViewFinder the central widget for a generic MainWindow. Just create a new project, and copy the mainwindow.ui fle from that.

The last posts from this poster were these, in 2016, and it is very unlikely he is still following this forum.