Important: Please read the Qt Code of Conduct -

the QCameraInfo::availableCameras() method not work when deploy the mac app

  • Hi:
    I developed a mac app use qt , my app needs to get the camera which belongs to the mac, when I debug my project, everything works fine that I get the camera which belongs to my mac , then I need to deploy the app, so I add the libqcocoa.dylib to the .app/Contents/PlugIns/platforms/ directory, and add the code to the main.cpp:

           QDir dir(QCoreApplication::applicationDirPath());

    and now I can deploy my app, my app can work on other mac, but I can't get the camera list, the QCameraInfo::availableCameras() method return result is 0 what is not I expect, so I change
    the code of main.cpp to :

           QDir dir(QCoreApplication::applicationDirPath());
       // QCoreApplication::setLibraryPaths(QStringList(dir.absolutePath()));

    now I can get the camera list, it makes me confused, can you give me some reason about this situation, if I want to deploy my app and let the QCameraInfo::availableCameras() method work, what should I do?

    thanks a lot!

  • Lifetime Qt Champion

    @Princein said in the QCameraInfo::availableCameras() method not work when deploy the mac app:


    is this really the directory name? As far as I know MacOS filesystem is case sensitive.

  • Lifetime Qt Champion


    On what version of macOS do you have that happening ?

  • @jsulm
    I think PlugIns is right, you can fine some information like this:

    Table 3-1  Standard locations for code inside a bundle
    Top content directory of the bundle
    Helper apps and tools
    Frameworks, dylibs
    Plug-ins, both loadable and extensions
    XPC services
    Helper apps and tools
    Automator actions
    Spotlight importers
    Installable login items
    Privileged helper tools installed by the ServiceManagement framework


  • @SGaist macOS Mojave Version 10.14.2 (18C54)

  • Lifetime Qt Champion

    Did you add the NSCameraUsageDescription to your Info.plist file ?

  • @SGaist yes, it seems is a mac app requesting Authorization question, so I add the ‘NSCameraUsageDescription’ to my app Info.plist by add code to my file:

    QMAKE_POST_LINK += plutil -replace NSCameraUsageDescription -string \"My usage description.\" $$DESTDIR/$${TARGET}.app/Contents/Info.plist

    and after generating the app, the 'NSCameraUsageDescription' key is in my app Info.plist which just as I want, when I rerun the app, but the app does not do anything, which I want is like in the link :

    In macOS 10.14 and later, the user must explicitly grant permission for each app to access cameras and microphones. Before your app can use the capture system for the first time, macOS shows an alert asking the user to grant your app access to the camera, as shown below. macOS remembers the user’s response to this alert, so subsequent uses of the capture system don’t cause it to appear again.

    in the, I know if I want to show the 'get aceess' alert,I should use the AVCaptureDevice authorizationStatus(for:) method in OC or Swift :

    Verify and Request Authorization for Capture
    Always test the AVCaptureDevice authorizationStatus(for:) method before setting up a capture session. If the user has not yet granted or denied capture permission, the authorization status is AVAuthorizationStatus.notDetermined. In this case, use the requestAccess(for:completionHandler:) method to have macOS prompt the user:

    switch AVCaptureDevice.authorizationStatus(for: .video) {
        case .authorized: // The user has previously granted access to the camera.
        case .notDetermined: // The user has not yet been asked for camera access.
            AVCaptureDevice.requestAccess(for: .video) { granted in
                if granted {
        case .denied: // The user has previously denied access.
        case .restricted: // The user can't grant access due to restrictions.

    but my mac project is Qt project, what should I do If I want to use the mac camera when deploying my app to other mac, thanks a lot!

  • @Princein it seems the QCameraInfo::availableCameras() method has bug :

    what should I do, if I want to get the camera list in mac in c++?

  • Lifetime Qt Champion

    @Princein This bug seems only to affect Linux

  • Moderators

    @Princein I think this is similar to an issue we had recently on this forum, can't quite find it atm, where the issue is with QtCreator.

    QtCreator would also need to request camera permission, has your app, when started from QtC is a child process of QtC.


  • now I develope a simple Qt project which named 'task2' on mac for test the QCameraInfo::availableCameras() method, I add the libqcocoa.dylib to the .app/Contents/PlugIns/platforms/ directory, and here is main.cpp in task2:

        QApplication a(argc, argv);
        QDir dir(QCoreApplication::applicationDirPath());
     //  dir.cdUp();
     //  QCoreApplication::setLibraryPaths(QStringList(dir.absolutePath()));
        MainWindow w;;
        return a.exec();

    I don't use the QCoreApplication::setLibraryPaths(QStringList(dir.absolutePath())); method now,it can deploy too, in myself mac, the QCameraInfo::availableCameras() method can return my camera on my mac which just as I expect,but when I deploy the task2 app to other mac which MacOS version is 10.13.6, the QCameraInfo::availableCameras() method can't return the camera on that mac, I really need the camera info on the mac, it seems a platform specific problem that can't use the OpenCV library get it, here is my code that gets the camera list in task2 project:

    void MainWindow::getCamera(){
        const QList<QCameraInfo> availableCameras = QCameraInfo::availableCameras();
        for (const QCameraInfo &cameraInfo : availableCameras) {
           QString deviceInfoStr = cameraInfo.description();
           cout << "deviceInfoStr:   " << deviceInfoStr.toStdString() << endl;
           QCameraInfo defaultCameraInfo = QCameraInfo::defaultCamera();
           QString defaultCameraInfoStr = defaultCameraInfo.description();
           cout << "defaultCameraInfoInfoStr:   " << defaultCameraInfoStr.toStdString() << endl;

    where is wrong? could you help me, thanks a lot!

  • @Princein my Mac MacOS version is 10.14.2 (18C54)

  • Lifetime Qt Champion

    You should check the bug report system to see if there's already something related to this. If not please open a new report providing a minimal compilable example as well as your findings so that it can be fixed.

Log in to reply