qt mac 解决 info.plist 自定义问题

qt 调用 ffmpeg 录音,遇到了权限问题折腾了挺长时间,记录下一个可用的方法,

在qt 创建的项目根目录创建 Info.plist 文件

xml 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>CFBundleDevelopmentRegion</key>
        <string>en</string>
        <key>CFBundleExecutable</key>
        <string>${EXECUTABLE_NAME}</string>
        <key>CFBundleIdentifier</key>
        <string>com.yourcompany.${PRODUCT_NAME:rfc1034identifier}</string>
        <key>CFBundleInfoDictionaryVersion</key>
        <string>6.0</string>
        <key>CFBundleName</key>
        <string>${PRODUCT_NAME}</string>
        <key>CFBundlePackageType</key>
        <string>APPL</string>
        <key>CFBundleShortVersionString</key>
        <string>1.0.0</string>
        <key>CFBundleVersion</key>
        <string>1</string>
        <key>LSMinimumSystemVersion</key>
        <string>${MACOSX_DEPLOYMENT_TARGET}</string>
        <key>NSPrincipalClass</key>
        <string>NSApplication</string>
        <key>NSHighResolutionCapable</key>
        <true/>
        <!-----上面的字段估计没有用 -->
        
        <!-- 权限字段 -->
        <key>NSCameraUsageDescription</key>
        <string>This app needs camera access to capture photos and videos</string>
        <key>NSCameraUseContinuityCameraDeviceType</key>
        <true/>
        <!-- <key>NSCameraUsageDescription</key>
        <string>需要相机权限来拍摄照片</string> -->
        <key>NSMicrophoneUsageDescription</key>
        <string>需要麦克风权限来录制音频</string>
        <key>NSLocationWhenInUseUsageDescription</key>
        <string>需要位置权限来提供定位服务</string>
        <key>NSPhotoLibraryUsageDescription</key>
        <string>需要访问照片库来保存和读取图片</string>
    </dict>
</plist>

.pro 文件

.pro 复制代码
QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++17

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp \
    mainwindow.cpp

HEADERS += \
    mainwindow.h

FORMS += \
    mainwindow.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

FFMPEG_HOME = /usr/local/Cellar/ffmpeg/7.1.1_2

INCLUDEPATH += $${FFMPEG_HOME}/include

LIBS += -L $${FFMPEG_HOME}/lib \
           -lavdevice \
           -lavformat \
           -lavcodec \
           -lavutil

# 设置 Info.plist 文件
QMAKE_INFO_PLIST = $$PWD/Info.plist

终于可以正常的拉起麦克风了

相关推荐
学而知不足~1 天前
FFmpeg03:多媒体文件处理基础
ffmpeg
dualven_in_csdn2 天前
ffmpeg编译
ffmpeg
Kevin Wang7272 天前
FFmpeg如何使用GPU加速
ffmpeg
feiyangqingyun3 天前
纯Qt结合ffmpeg实现本地摄像头采集/桌面采集/应用程序窗口采集/指定采集帧率和分辨率等
qt·ffmpeg·qt桌面采集·qt摄像头采集·qt程序窗口采集
shelutai3 天前
ubuntu 编译ffmpeg6.1 增加drawtext,libx264,libx265等
linux·ubuntu·ffmpeg
陆远方3 天前
AttributeError: module ‘ffmpeg‘ has no attribute ‘probe‘
ffmpeg
进击ing小白3 天前
FFmpeg的基本概述(二)
ffmpeg
OperateCode6 天前
AutoVideoMerge:让二刷更沉浸的自动化视频处理脚本工具
python·opencv·ffmpeg
胡耀超7 天前
DataOceanAI Dolphin(ffmpeg音频转化教程) 多语言(中国方言)语音识别系统部署与应用指南
python·深度学习·ffmpeg·音视频·语音识别·多模态·asr