Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How can I fix bug camera in Qt5.13.1?



  • I wanna adjust exposure related settings in my camera. For example I try to use function "camera.searchAndLock()" but it doesn't work.

    I tried to run camera example of Qt, but for the following code I have always "Unlocked" status.

    switch (m_camera->lockStatus()) {
        case QCamera::Searching:
        case QCamera::Locked:
            m_camera->unlock();
            break;
        case QCamera::Unlocked:
            m_camera->searchAndLock();
        }
    

    I write the following QML codes, but the following code always return "unlocking focus".

    if (camera.lockStatus == Camera.Unlocked) {
        camera.searchAndLock();
        console.log("searching focus...")                                
       }                                 
       else {                           
            camera.unlock();                        
            console.log("unlocking focus...")                            
         }
    

    I want to change exposure related settings in my camera by the following codes, but all of them do not work:

    camera.searchAndLock()    
    camera.exposure.exposureCompensation = value
    camera.exposure.spotMeteringPoint.x=value
    camera.exposure.spotMeteringPoint.y=value
    camera.exposure.manualShutterSpeed = value
    camera.exposure.iso  = value
    camera.exposure.manualAperture=value
    

    I try to use "searchAndLock()" function for start focusing, exposure calculation, but after running this function status of my camera is still "Unlocked" rather "Searching".

    What can I do with this bug? Which version of Qt I can install that doesn't has this bug?

    I was success to fix bug of "SerialPort" by read this link:
    https://stackoverflow.com/questions/58020663/how-to-make-qserialport-from-qt5-13-1-work

    Is there a way for fix this bug by me?

    Qt Version: Qt 5.13.1 (MSVC 2017, 32 bit),
    Platform: Windows 10


  • Lifetime Qt Champion



  • @jsulm

    I try to use the following code for show list the lock types, camera supports, but it has a lot error like:

    'const_iterator': is not a member of 'QFlags<QCamera::LockType>'
    
     'i': is not a member of 'QtPrivate::QForeachContainer<QFlags<QCamera::LockType>>'
    
    QFlags<QCamera::LockType> lockTypesCamera = m_camera->supportedLocks();
    
        foreach (QCamera::LockType &lockType, lockTypesCamera) {
             qDebug()<<lockType;
        }
    

  • Lifetime Qt Champion

    @neda

    auto lockTypesCamera = m_camera->supportedLocks();
    
    for (auto &lockType : lockTypesCamera) {
         qDebug() << static_cast<int>(lockType);
    }
    


  • @jsulm said in How can I fix bug camera in Qt5.13.1?:

    auto lockTypesCamera = m_camera->supportedLocks();

    for (auto &lockType : lockTypesCamera) {
    qDebug() << static_cast<int>(lockType);
    }

    New error:

    
    error: invalid range expression of type 'QFlags<QCamera::LockType>'; no viable 'begin' function available
    
    auto lockTypesCamera = m_camera->supportedLocks();
    
        for (auto &lockType : lockTypesCamera) {
             qDebug() << static_cast<int>(lockType);
        }
    

    I try the following code, but it has error too.

    auto lockTypesCamera = m_camera->supportedLocks();
    foreach (auto &lockType, lockTypesCamera) {
            qDebug() << static_cast<int>(lockType);
        }
    
     error: C2039: 'const_iterator': is not a member of 'QFlags<QCamera::LockType>'
    

  • Lifetime Qt Champion

    @neda Well, it can't work like this as flags are bit-maps.

    auto lockTypesCamera = m_camera->supportedLocks();
    if (lockTypesCamera == QCamera::NoLock) {
        qDebug() << "NoLock";
    } else {
        if (lockTypesCamera | QCamera::LockExposure) {
            qDebug() << "LockExposure";
        }
        if lockTypesCamera | QCamera::LockWhiteBalance) {
            qDebug() << "LockWhiteBalance";
        }
        if (lockTypesCamera | QCamera::LockFocus) {
            qDebug() << "LockFocus";
        }
    }
    


  • @jsulm said in How can I fix bug camera in Qt5.13.1?:

    auto lockTypesCamera = m_camera->supportedLocks();
    if (lockTypesCamera == QCamera::NoLock) {
    qDebug() << "NoLock";
    } else {
    if (lockTypesCamera | QCamera::LockExposure) {
    qDebug() << "LockExposure";
    }
    if lockTypesCamera | QCamera::LockWhiteBalance) {
    qDebug() << "LockWhiteBalance";
    }
    if (lockTypesCamera | QCamera::LockFocus) {
    qDebug() << "LockFocus";
    }
    }

    Thanks
    It return "NoLock", but my camera has a windows application.
    That application can adjust exposure related settings.
    How can they change exposure related settings without change lock status?

    I want to change exposure related settings in my camera by the following codes, but all of them do not work:

    camera.searchAndLock()    
    camera.exposure.exposureCompensation = value
    camera.exposure.spotMeteringPoint.x=value
    camera.exposure.spotMeteringPoint.y=value
    camera.exposure.manualShutterSpeed = value
    camera.exposure.iso  = value
    camera.exposure.manualAperture=value
    

  • Lifetime Qt Champion

    @neda Can be that Qt does not support your camera properly.

    "How can they change exposure related settings without change lock status?" - I guess that app does not use Qt and communicates directly with the camera through a low level API.

    See https://doc.qt.io/qt-5/qtmultimedia-windows.html
    "Basic features such as displaying a viewfinder and capturing a still image are supported, however, majority of camera controls are not implemented."



  • @jsulm
    Thank you very much.



  • @jsulm

    Thanks a lot
    And last question
    I should solve this problem, I have to write a program that works with this camera.
    Do I have to be disappointed with Qt?
    Do you suggest other language or editor?
    Which programming language or editor do you recommend?


  • Lifetime Qt Champion

    @neda said in How can I fix bug camera in Qt5.13.1?:

    Do I have to be disappointed with Qt?

    Well, it is like it is, Qt does not have support for everything.

    "Do you suggest other language or editor?" - this is not related to programming language and even less to an editor.
    You need to check what is available for your camera: does the manufacturer provide any SDK, client libraries, drivers, ...?
    If there is a SDK/client lib for C/C++ you can use it in your Qt app as any other C/C++ lib.



  • @jsulm Thank you very much.



  • @neda if you're done with the issue please don't forget to mark your post as solved. Thanks.



  • @jsulm

    I found this project.
    https://www.codeproject.com/Articles/125478/Versatile-WebCam-C-library?msg=4123457#xx4123457xx
    I tested my camera with this project.
    Every thing was ok and I can changed all settings of camera.
    This project use WebCamLib – it is a C++ project with just two files (WebCamLib.h and WebCamLib.cpp) that queries a WebCam using DirectShow and returns results.
    I think maybe I can use this library or even WebCamLib's source in my project rather start new project with c#, because I have to run my application by this camera.
    Do you think is possible?
    Would you please guide me that how can I use WebCamLib's source in my project ?


  • Lifetime Qt Champion

    @neda said in How can I fix bug camera in Qt5.13.1?:

    Do you think is possible?

    It looks more like C# lib. Which exact C++ library do you mean?



  • @jsulm said in How can I fix bug camera in Qt5.13.1?:

    It looks more like C# lib. Which exact C++ library do you mean?

    WebCamLib - This is a C ++ project.
    Is there a way on how to overwrite this project in Qt?


  • Lifetime Qt Champion

    @neda said in How can I fix bug camera in Qt5.13.1?:

    Is there a way on how to overwrite this project in Qt?

    If it is C++ you can use it as any other C++ code or library. Either add the source code to your project or build it as library and add library to your project.



  • @neda said in How can I fix bug camera in Qt5.13.1?:

    I wanna adjust exposure related settings in my camera. For example I try to use function "camera.searchAndLock()" but it doesn't work.

    1. What hardware are you using (i.e. webcam attached to USB, Android phone camera, Raspberry Pi camera, etc.)?

    2. Are you positive that the underlying hardware allows for all those settings (i.e. focus lock, exposure, manual shutter, etc.)?

    3. Have you tried that same hardware with a different (non-Qt) application?


Log in to reply