0

Currently I'm trying to make an mobile app and I need to turn on the flash light of a mobile device. Actually I want to use it as a torch(On/off/blink etc). I searched in the qt docs and found QCamera class. But I'm unable to turn the light on. I'm using Qt 6.3.1. Can anyone help?

I'm doing something like this:


// In constructor of a widget class,
cam = new QCamera(QCameraDevice::BackFace, this); //cam is declared in the header file

// In a function, called after a button click,
// cam->setFlashMode(QCamera::FlashOn);
cam->setTorchMode(QCamera::TorchOn);
cam->start();

I added this code inside a function and called it after a button-click event. But when I click the button, nothing happens.

UPD: What I have found interesting is, I've tried printing the return value of isFlashModeSupported() and it returns false!

QString str = cam->isFlashModeSupported(QCamera::FlashOn) ? "Flash: Yes" : "Flash: No";
ui->Flash->setText(str); // str = "Flash: No"

I'm using a phone which has controllable flash light. So what can be the reason for this kind of behaviour?

  • This might be interesting as well: [QCamera::isTorchModeSupported()](https://doc.qt.io/qt-6/qcamera.html#isTorchModeSupported). – Scheff's Cat Jul 14 '22 at 11:21
  • @Scheff'sCat I did what you said and got an interesting result. `QCamera::isTorchModeSupported()` returns false though I have tested on a phone with controllable flash light. – Mysterious Bits Jul 14 '22 at 19:15

0 Answers0