Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. What is this QML code doing?
Forum Updated to NodeBB v4.3 + New Features

What is this QML code doing?

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mynameisjohn
    wrote on last edited by
    #1

    Hello All,

    I'm working on a mobile platform (Android) and trying to access the camera via the C++ Multimedia classes like QCamera. However, I only have success opening my device's camera when I use the declarative-camera example, which uses a QML script. As far as I can tell, the code needed to display incoming frames in a viewfinder is

    @VideoOutput {
    id: video
    anchors.fill: parent
    source: camera

        Camera {
            id: camera
        }
    }@
    

    I was wondering if anyone knew how to translate this code to c++; I tried the following, but I'm having no luck:

    @int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    QCamera * camera;
    QCameraViewfinder * viewFinder;
    
    QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
    foreach (const QCameraInfo &cameraInfo, cameras) {
        qDebug() << cameraInfo.deviceName();
        // I know the "front" camera exists
        if (cameraInfo.deviceName() == "front"){
            camera = new QCamera(cameraInfo);
            qDebug() << "added the front camera";
        }
    }
    
    viewFinder = new QCameraViewfinder;
    camera->setViewfinder(viewFinder);
    
    viewFinder->show();
    viewFinder->resize(640,480);
    
    camera->start();
    
    return a.exec&#40;&#41;;
    

    }@

    Are there any other steps I need to take? The QML code specifies much less, but it actually works, so I was a bit confused.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MartynW
      wrote on last edited by
      #2

      There are some issues grabbing frames on Android which are discussed in the thread http://qt-project.org/forums/viewthread/35116/ and towards the end I include some code for setting up and starting the camera which may help you. The code generates a QImage for each frame, so its up to you how you display it.

      Good luck!

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mynameisjohn
        wrote on last edited by
        #3

        Thank you, that is helpful. I did end up going with a QVideoProbe based solution, but it seems like your solution gets around using QML (which is something I'd like to do.)

        edit:
        Can you elaborate a bit on what setting SuppressVideo does in the code? I'd just like to verify that you're using your own QAbstractVideoSurface in conjunction with the QVideoProbe and QCamera. I've tried something similar, but I never know if I'm implementing the abstract class correctly.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved