Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QCamera black screen or turns off
Qt 6.11 is out! See what's new in the release blog

QCamera black screen or turns off

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 2.0k 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
    Mark58
    wrote on last edited by
    #1

    Hello,

    I know there are already a lot of posts about Qmultimedia and black screens, but I can't find a solution for my problem. I'm using Qt5.13.0.

    I try to make a simple application with QCamera.
    This is the code:

    #include <QApplication>
    #include <QCamera>
    #include <QCameraViewfinder>
    #include <QCameraInfo>
    
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
    
        QCamera camera;
        QCameraViewfinder viewfinder;
        viewfinder.show();
        camera.setViewfinder(&viewfinder);
        camera.start();
    
        qDebug() << "error: " <<camera.error() <<
                    "\n state:" << camera.state() <<
                    "\n status: " << camera.status() <<
                    "\n errorstring: " << camera.errorString() <<
                    "\n camptureMode: " << camera.captureMode() <<
                    "\n camera.lockStatus: " << camera.lockStatus() <<
                    "\n availableMetaData: " << camera.availableMetaData();
        return app.exec();
    }
    

    When I run the program, I only get a black screen, but no error message (see screenshot with debug-info).
    screenshot.PNG

    It seems to me that the camera is not switched on.
    Then I tried to run the .exe-File (camera_simple.exe) without QCreator. Interestingly, I get a picture and the camera works for about 5 seconds. Then the picture freezes and the camera turns off (green light next to the camera is gone).

    What is wrong?

    Thanks for your help.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Are you sure you are creating a valid QCamera object ? In anycase, I would recommend following the QCamera example using the list of available cameras to select one you have on your system. See here.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

        Hi,
        thanks for your answer.

        I tried to follow the QCamera example and so I changed my code. The result is the same (still black screen). I have only one camera (laptop internal camera).
        Code:

        int main(int argc, char *argv[])
        {
            QApplication app(argc, argv);
        
            QCamera *camera;
            const QList<QCameraInfo> cameras = QCameraInfo::availableCameras();
            for (const QCameraInfo &cameraInfo : cameras) {
                qDebug() << "cameraInfo.deviceName: "<< cameraInfo.deviceName();
                camera = new QCamera(cameraInfo);
            }
            QCameraViewfinder viewfinder;
            viewfinder.show();
            camera->setViewfinder(&viewfinder);
            camera->start();
        
            qDebug() << "error: " <<camera->error() <<
                            "\n state:" << camera->state() <<
                            "\n status: " << camera->status() <<
                            "\n errorstring: " << camera->errorString() <<
                            "\n camptureMode: " << camera->captureMode() <<
                            "\n camera.lockStatus: " << camera->lockStatus() <<
                            "\n availableMetaData: " << camera->availableMetaData() <<
                            "\n camera.isAvailable: " << camera->isAvailable() <<
                            "\n viewfinder.isEnabled: "<< viewfinder.isEnabled() <<
                            "\n viewfinder.isVisible: " <<viewfinder.isVisible();
        
            return app.exec();
        }
        

        debug-information:

        cameraInfo.deviceName:  "@device:pnp:\\\\?\\usb#vid_04f2&pid_b5c0&mi_00#6&34052049&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\\global"
        error:  QCamera::NoError 
         state: QCamera::ActiveState 
         status:  QCamera::ActiveStatus 
         errorstring:  "" 
         camptureMode:  QFlags(0x1) 
         camera.lockStatus:  QCamera::Unlocked 
         availableMetaData:  ()
         camera.isAvailable:  true 
         viewfinder.isEnabled:  true 
         viewfinder.isVisible:  true
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Are you on Windows ?
          By the way, did you try a more recent version of Qt ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mark58
            wrote on last edited by
            #5

            Yes, I'm using Windows10.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              What kind of camera is that ?

              Do you have it working properly with e.g. VLC ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • Ashok KumarA Offline
                Ashok KumarA Offline
                Ashok Kumar
                wrote on last edited by
                #7

                This code is working perfectly in Qt 5.12.0.

                1 Reply Last reply
                1
                • M Offline
                  M Offline
                  Mark58
                  wrote on last edited by
                  #8

                  Thanks for your answers and your help.

                  I'm using the internal camera of a Lenovo T470.
                  VLC - I did not test ist. But meanwhile I installed gstreamer 1.0 and everything was working fine.

                  After that I found out that there is a common known problem with Lenovo-laptops and the camera. I found the solution (adding two values in the regedit) and no it's working fine.

                  1 Reply Last reply
                  2

                  • Login

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