Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Accessing the Android Camera in Qt
Qt 6.12 LTS is out! See what's new in the release blog

Accessing the Android Camera in Qt

Scheduled Pinned Locked Moved Mobile and Embedded
16 Posts 5 Posters 21.5k 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.
  • V Offline
    V Offline
    Vincent007
    wrote on last edited by
    #2

    try $QTPATH\Examples\Qt-5.3\multimedia\declarative-camera

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #3

      Wow! Err...Thank you very much. I was making things far too complicated...

      Also thanks for prompting me to look at the examples, there's some pretty neat stuff in here. Qt is not to be underestimated.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #4

        Hey, I consider this answered, but as a follow up does anyone have some advice on porting the qml in that example to c++? I'm looking at the advice on the Camera overview page (http://qt-project.org/doc/qt-5/cameraoverview.html), but the code snippets there aren't enough to get my app up and grabbing frames. Here's what I've got:

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

        QCameraViewfinder * viewFinder;
        QCamera * camera;
        

        /* This did not help
        QByteArray cameraDevice;
        foreach(const QByteArray &deviceName, QCamera::availableDevices()) {
        if (cameraDevice.isEmpty())
        cameraDevice = deviceName;
        }
        */

        camera = new QCamera(); //(cameraDevice);
        viewFinder = new QCameraViewfinder;
        
        camera->setViewfinder(viewFinder);
        viewFinder->show();
        camera->start();
        
        return a.exec();
        

        }@

        I was getting an unable to connect error. That's gone away, but I'm still just seeing a blank screen. I feel like the code above is a bit too simple, but I don't know what other steps are required.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Vincent007
          wrote on last edited by
          #5

          try $QTPATH\Examples\Qt-5.3\multimediawidgets\camera

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #6

            At least now I don't have to feel completely crazy...the example loads but I see no video. When I press "Record" I get an error:

            W/IMediaDeathNotifier(25594): media server died
            W/CameraBase(25594): Camera service died!
            W/CameraBase(25594): mediaserver's remote binder Camera object died
            E/Camera (25594): Error 100'

            Under devices I can see the front facing camera being detected and if I toggle it I get an error. When I try and re-initialize it I see

            W/CameraBase(28429): An error occurred while connecting to camera: 0
            D/Qt Camera(28429): Fail to connect to camera service
            W/Qt (28429): thread/qthread.cpp:425 (virtual QThread::~QThread()): QThread: Destroyed while thread is still running

            It could just be my device - I've heard there are some issues with the Nexus 7 camera, and I remember reading that the Front Facing camera is labelled 1 rather than 0, so it may be that. Thank you for the help. I'll play around with this example and maybe try it on another device if I can find one.

            1 Reply Last reply
            0
            • V Offline
              V Offline
              Vincent007
              wrote on last edited by
              #7

              try to reboot your device first.

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #8

                Hmm, I tried rebooting twice and made sure both times that camera was the only app running. I am deploying the app from Qt creator directly using Qt version 5.3, and as far as I know the example you suggested has not been modified.

                1 Reply Last reply
                0
                • mrdebugM Offline
                  mrdebugM Offline
                  mrdebug
                  wrote on last edited by
                  #9

                  I have a similar problem. I have wrote an application using declarative to watch my webcam. This application works on my pc but I obtain nothing in my mobile.

                  Need programmers to hire?
                  www.labcsp.com
                  www.denisgottardello.it
                  GMT+1
                  Skype: mrdebug

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #10

                    declarative actually worked out of the box for me, which is why I'm confused. The fairly simple QML code had no trouble finding the camera on my device, so I'm debating whether or not I should look at the source of the QML Camera object to see what's going on there.

                    I will also try and run the camera app on my desktop with a webcam just to verify that it works.

                    1 Reply Last reply
                    0
                    • ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #11

                      No luck on a Nexus 4...I must be doing something wrong. If I ever figure it out I'll report back.

                      edit: I assume nothing special needs to be done regarding Permissions in the Manifest; there is a comment in the generated file that seems to indicate Qt takes care of this based on the needs of your app.

                      1 Reply Last reply
                      0
                      • V Offline
                        V Offline
                        Vincent007
                        wrote on last edited by
                        #12

                        https://bugreports.qt-project.org/browse/QTBUG-38942

                        bq. Using Qt Multimedia with QWidgets has never been really supported on Android. You'll have to stick to QML for now. We'll add support for QWidget in 5.4.0. https://codereview.qt-project.org/#change,85577 makes sure the device doesn't get into an undefined state when trying to take a picture without a valid viewport.

                        1 Reply Last reply
                        0
                        • ? Offline
                          ? Offline
                          A Former User
                          wrote on last edited by
                          #13

                          I see. Thank you very much for your help, Vincent. Perhaps I'll explore getting the VideoOutput from the QML Camera as a buffer somehow.

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            Mr Aloof
                            wrote on last edited by
                            #14

                            do u success?
                            i need it to
                            but i failed to convert the buffer to a QImage
                            [quote author="mynameisjohn" date="1401803722"]I see. Thank you very much for your help, Vincent. Perhaps I'll explore getting the VideoOutput from the QML Camera as a buffer somehow. [/quote]

                            1 Reply Last reply
                            0
                            • N Offline
                              N Offline
                              Nick007
                              wrote on last edited by
                              #15

                              Hello!
                              How can I get video output from QML Camera?
                              I can get QMetaObject in C++ and get some properties of Camera, but there is no videoSurface or setViewfinder methods... I wonder, how QML Camera send data to VideoOutput???

                              1 Reply Last reply
                              0
                              • N Offline
                                N Offline
                                Nick007
                                wrote on last edited by
                                #16

                                Hello!
                                How can I get video output from QML Camera?
                                I can get QMetaObject in C++ and get some properties of Camera, but there is no videoSurface or setViewfinder methods... I wonder, how QML Camera send data to VideoOutput???

                                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
                                • Unsolved