1

I need to know how to turn on camera flash light or torch light using qt ? Is there any way to do this ? I am using qt 5.5. Please give suggestion.

Here is My code

#include "flashon.h"

FlashOn::FlashOn()
{
    cam = new QCamera;
    camExpos = cam->exposure ();
}

FlashOn::~FlashOn()
{
    delete this;
}

void FlashOn::lightOn()
{
    camExpos->setFlashMode (QCameraExposure::FlashOn);
    qDebug() << " light is on ";
}
  • http://stackoverflow.com/help/how-to-ask – Dmitry Sazonov May 14 '16 at 18:58
  • Please be more specific. Ex. Device, deployment, etc. – Nicholas Johnson May 15 '16 at 15:21
  • I am building an cross platform app to turn on camera flash light. My code is very simple, but it does not work. What can I do ? –  May 16 '16 at 05:21
  • You can implement a objective c file into your C++ app (or something else), and then use the tibidabo solution here: https://stackoverflow.com/questions/5882829/how-to-turn-the-iphone-camera-flash-on-off – peter70 Feb 26 '19 at 15:00

1 Answers1

1

Well, if you read the documentation, there's QCameraExposure::FlashTorch in QCameraExposure::FlashModes.

camExpos->setFlashMode(QCameraExposure::FlashTorch);

All devices may not support it:

QCameraExposure::FlashTorch - 0x20 - Constant light source. If supported, torch can be enabled without loading the camera.

So you probably want to check to see if it is available:

if (!camExpos->isFlashModeSupported(QCameraExposure::FlashTorch)) {
    // ...not supported...
}
  • I have edited like this but no luck cam->start (); if(camExpos->isFlashModeSupported (QCameraExposure::FlashTorch)){ camExpos->setFlashMode (QCameraExposure::FlashTorch); } –  May 16 '16 at 12:52
  • @coder_hasib Well, if you edited it did you ensure that isFlashModeSupported returned true for the torch mode, such that the setFlashMode is being called? – HostileFork says dont trust SE May 16 '16 at 13:16
  • I have checked but still no luck if(camExpos->isFlashModeSupported (QCameraExposure::FlashTorch)){ qDebug() << "Flash supported"; QMessageBox::information (this, "Info", "Flash supported", QMessageBox::Ok); camExpos->setFlashMode (QCameraExposure::FlashTorch); } else { qDebug() << "Flash not supported"; QMessageBox::information (this, "Info", "Flash not supported", QMessageBox::Ok); } I got flash not supported, but i have a flash light on this android mobile. where is the problem ? –  May 17 '16 at 13:15
  • @coder_hasib If what you are trying to say is that you got "Flash supported" and it didn't work, then I would suggest you work from a complete example like the [Qt Camera Example](http://doc.qt.io/qt-5/qtmultimedia-multimediawidgets-camera-example.html). I didn't check before, but it seems there may be [more involved](http://doc.qt.io/qt-5/qtmultimedia-multimediawidgets-camera-camera-cpp.html) in setting up a valid camera instance than `new QCamera`, e.g. `new QCamera (QCameraInfo::defaultCamera())`. So make sure you can run a working demo before trying this specific tweak. – HostileFork says dont trust SE May 17 '16 at 13:22
  • I am sorry, I have read but can not find camera expose or anything related. –  May 19 '16 at 05:22