I have qml camera widget in camera.qml. the qml component is loaded from a Qt widget "WidgetCamera" that is placed on a stack widget in the background. The widget starts the camera device already at creation.
How to make the camera start only when the widget is shown in the foreground. And vice versa, how release the camera when the widget goes to the background?
camera.qml
Item {
width: 640
height: 360
Camera {
id: camera
}
VideoOutput {
source: camera
anchors.fill: parent
}
}
widgetCamera.h
class WidgetCamera : public QWidget
{
Q_OBJECT
public:
WidgetCamera() {
QQuickWidget *qw= new QQuickWidget;
qw->setSource(QUrl("qrc:///camera.qml"));
// ...
}
}
mainwindow.h
class MainWindow : QMainWindow
{
Q_OBJECT
public:
MainWindow() {
QStackedWidget *sw = new QStackedWidget;
sw->addWidget(new QWidget());
sw->addWidget(new WidgetCamera());
// ...
}
}