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

How to get USB camera to be default



  • Hello, I am working on an embedded board and inside the board it has a /dev/video0 and a /dev/video1 by default. I then plug in my USB camera and it usually is /dev/video2. My current code is taking the deafult camera and (which I want to be the USB camera) thinking it is the /dev/video0.

    My code:

    int find_device(){
        QString device_name;
        std::string defaultDevice;
        const QList<QCameraInfo> availableCameras = QCameraInfo::availableCameras();
        for (const QCameraInfo &cameraInfo : availableCameras) {
            if (cameraInfo == QCameraInfo::defaultCamera()){
                   device_name = QCameraInfo::defaultCamera().deviceName();
                   defaultDevice = device_name.toStdString();
            }
        }
    

    Does anyone know how I would edit this to make the USB camera the one it defaults to or how it could find it? I dont think QCamerainfo::devicename will work for me because there are multiple USB cameras I plug in that have different names.


  • Lifetime Qt Champion

    Hi,

    That is something that you have to setup on your system. If using udev for example, write a rule that gives a meaningful name to that camera and use that in your software.


Log in to reply