c++qtqtmultimediaqcamera

QCamera::start gives mysterious "failed to start" log message


It's just plain luck my program is so simple, so I eventually found out what causes the mysterious log message. My program log looks like this:

Debugging starts
failed to start
Debugging has finished

Which happens after:

camera = new QCamera(QCameraInfo::defaultCamera());
// see http://omg-it.works/how-to-grab-video-frames-directly-from-qcamera/
camera->setViewfinder(frameGrabber = new CameraFrameGrabber());
camera->start();

The start() method causes this message in console. Now the meaning of the message is obvious, what it's not very helpful. What steps should I take to troubleshoot it?


Solution

  • Reasons for this might differ, but in my case it was simply because I provided invalid QCameraInfo. The culprit is that QCameraInfo::defaultCamera() might return invalid value if Qt fails to detect any cameras on your system, which unfortunately happens even if cameras are present.