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. the QCameraInfo::availableCameras() method not work when deploy the mac app
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 4 Posters 2.5k 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.
  • P Princein

    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());
           dir.cdUp();
           dir.cd("PlugIns");
           QCoreApplication::setLibraryPaths(QStringList(dir.absolutePath()));
    

    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());
           dir.cdUp();
           dir.cd("PlugIns");
       // 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!

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #2

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

    PlugIns

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

    https://forum.qt.io/topic/113070/qt-code-of-conduct

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

      Hi,

      On what version of macOS do you have that happening ?

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

      P 1 Reply Last reply
      0
      • jsulmJ jsulm

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

        PlugIns

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

        P Offline
        P Offline
        Princein
        wrote on last edited by
        #4

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

        
        Table 3-1  Standard locations for code inside a bundle
        Location
        Description
        Contents
        Top content directory of the bundle
        Contents/MacOS
        Helper apps and tools
        Contents/Frameworks
        Frameworks, dylibs
        Contents/PlugIns
        Plug-ins, both loadable and extensions
        Contents/XPCServices
        XPC services
        Contents/Helpers
        Helper apps and tools
        Contents/Library/Automator
        Automator actions
        Contents/Library/Spotlight
        Spotlight importers
        Contents/Library/LoginItems
        Installable login items
        Contents/Library/LaunchServices
        Privileged helper tools installed by the ServiceManagement framework
        
        

        in https://developer.apple.com/library/archive/documentation/Security/Conceptual/CodeSigningGuide/Procedures/Procedures.html#//apple_ref/doc/uid/TP40005929-CH4-SW2

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          On what version of macOS do you have that happening ?

          P Offline
          P Offline
          Princein
          wrote on last edited by
          #5

          @SGaist macOS Mojave Version 10.14.2 (18C54)

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

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

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

            P 1 Reply Last reply
            0
            • SGaistS SGaist

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

              P Offline
              P Offline
              Princein
              wrote on last edited by
              #7

              @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 app.pro 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
              https://docs-assets.developer.apple.com/published/663cb677e7/3d0e288c-9d77-4523-b1ec-bf42bca85cf1.png in the link :
              https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/requesting_authorization_for_media_capture_on_macos

              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 https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/requesting_authorization_for_media_capture_on_macos, 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.
                      self.setupCaptureSession()
                  
                  case .notDetermined: // The user has not yet been asked for camera access.
                      AVCaptureDevice.requestAccess(for: .video) { granted in
                          if granted {
                              self.setupCaptureSession()
                          }
                      }
                  
                  case .denied: // The user has previously denied access.
                      return
                  case .restricted: // The user can't grant access due to restrictions.
                      return
              }
              

              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!

              J.HilkJ 1 Reply Last reply
              0
              • P Princein

                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());
                       dir.cdUp();
                       dir.cd("PlugIns");
                       QCoreApplication::setLibraryPaths(QStringList(dir.absolutePath()));
                

                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());
                       dir.cdUp();
                       dir.cd("PlugIns");
                   // 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!

                P Offline
                P Offline
                Princein
                wrote on last edited by
                #8

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

                https://bugs.launchpad.net/canonical-developer-experience/+bug/1438072

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

                jsulmJ 1 Reply Last reply
                0
                • P Princein

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

                  https://bugs.launchpad.net/canonical-developer-experience/+bug/1438072

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

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  @Princein This bug seems only to affect Linux

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • P Princein

                    @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 app.pro 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
                    https://docs-assets.developer.apple.com/published/663cb677e7/3d0e288c-9d77-4523-b1ec-bf42bca85cf1.png in the link :
                    https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/requesting_authorization_for_media_capture_on_macos

                    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 https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/requesting_authorization_for_media_capture_on_macos, 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.
                            self.setupCaptureSession()
                        
                        case .notDetermined: // The user has not yet been asked for camera access.
                            AVCaptureDevice.requestAccess(for: .video) { granted in
                                if granted {
                                    self.setupCaptureSession()
                                }
                            }
                        
                        case .denied: // The user has previously denied access.
                            return
                        case .restricted: // The user can't grant access due to restrictions.
                            return
                    }
                    

                    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!

                    J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by
                    #10

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

                    IIRC


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      Princein
                      wrote on last edited by
                      #11

                      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();
                       //  dir.cd("PlugIns");
                       //  dir.cd("platforms");
                       //  QCoreApplication::setLibraryPaths(QStringList(dir.absolutePath()));
                          MainWindow w;
                          w.show();
                      
                          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();
                             ui->label->setText(deviceInfoStr);
                             cout << "deviceInfoStr:   " << deviceInfoStr.toStdString() << endl;
                           }
                             QCameraInfo defaultCameraInfo = QCameraInfo::defaultCamera();
                             QString defaultCameraInfoStr = defaultCameraInfo.description();
                             cout << "defaultCameraInfoInfoStr:   " << defaultCameraInfoStr.toStdString() << endl;
                             ui->label_2->setText(defaultCameraInfoStr);
                      }
                      
                      

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

                      P 1 Reply Last reply
                      0
                      • P Princein

                        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();
                         //  dir.cd("PlugIns");
                         //  dir.cd("platforms");
                         //  QCoreApplication::setLibraryPaths(QStringList(dir.absolutePath()));
                            MainWindow w;
                            w.show();
                        
                            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();
                               ui->label->setText(deviceInfoStr);
                               cout << "deviceInfoStr:   " << deviceInfoStr.toStdString() << endl;
                             }
                               QCameraInfo defaultCameraInfo = QCameraInfo::defaultCamera();
                               QString defaultCameraInfoStr = defaultCameraInfo.description();
                               cout << "defaultCameraInfoInfoStr:   " << defaultCameraInfoStr.toStdString() << endl;
                               ui->label_2->setText(defaultCameraInfoStr);
                        }
                        
                        

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

                        P Offline
                        P Offline
                        Princein
                        wrote on last edited by
                        #12

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

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

                          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.

                          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

                          • Login

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