Important: Please read the Qt Code of Conduct -

QCamera black screen or turns off

  • 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;;
        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).

    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.

  • Lifetime Qt Champion


    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.

  • 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).

    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;;
        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();


    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

  • Lifetime Qt Champion

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

  • Yes, I'm using Windows10.

  • Lifetime Qt Champion

    What kind of camera is that ?

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

  • This code is working perfectly in Qt 5.12.0.

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

Log in to reply