Book Image

QT5 Blueprints

By : Symeon Huang
Book Image

QT5 Blueprints

By: Symeon Huang

Overview of this book

Table of Contents (17 chapters)
Qt 5 Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

QML camera


So far, we talked about how to access and control the camera in Qt/C++. Now it's time to see how QML does in this area. Although there are some limitations, you'll find it's much easier and more elegant to do this in Qt Quick/QML because of the many packages that Qt has to offer.

Create a new Qt Quick application project. The main.qml content is shown as follows:

import QtQuick 2.3
import QtQuick.Controls 1.2
import QtMultimedia 5.3
import "qrc:/"

ApplicationWindow {
  visible: true
  width: 640
  height: 480
  title: qsTr("QML Camera Demo")

  Camera {
    id: camera

    imageCapture {
      onImageCaptured: {
        photoPreview.source = preview
        photoPreview.visible = true;
        previewTimer.running = true;
      }
    }
  }

  VideoOutput {
    id: viewfinder
    source: camera
    anchors.fill: parent
  }

  Image {
    id: photoPreview
    anchors.fill: viewfinder
  }

  Timer {
    id: previewTimer
    interval: 2000
    onTriggered: photoPreview.visible = false...