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

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

相关推荐
开开心心就好6 小时前
本地文件搜索工具推荐,占用小速度还快
智能手机·ffmpeg·ocr·word·音视频·网络攻击模型·安全架构
我科绝伦(Huanhuan Zhou)8 小时前
oracle坏块导致备份不了
数据库·oracle·ffmpeg
RS迷途小书童10 小时前
Python+FFmpeg提取大疆无人机MP4内嵌mov_text遥测SRT字幕并做完整性校验
python·ffmpeg·大疆·srt字幕·dji
开开心心就好10 小时前
视频压缩工具推荐,画质效果很能打
智能手机·ffmpeg·ocr·word·排序算法·音视频·散列表
可乐鸡翅yeah_1 天前
业务中 M3U8 水印相关坑,硬水印和动态水印区别
前端·网络·数据库·ffmpeg·m3u8在线
redfred1 天前
HyperFrames 部署教程:5.6 万 Star 开源「写 HTML 出视频」框架,Windows 从零上手(CLI 三条命令 + 7 个避坑)
ffmpeg·开源·自动化·html·音视频
Arcai10241 天前
PostgreSQL数据备份和恢复完全指南
数据库·postgresql·ffmpeg·备份一体机·备份软件·smartstor·智备科技
可乐鸡翅yeah_2 天前
FFmpeg 生成 HLS 独立分片 independent‑segments 参数到底有什么用
javascript·ffmpeg·音视频·safari·m3u8
企业数字化笔记2 天前
视觉处理为什么会慢?解码、预处理、模型推理、后处理和编码的性能拆解
ffmpeg·gpu算力
Maynor9963 天前
6张商品图→17秒带货短视频:开源12个Claude Skills,配音、字幕花字、BGM本地一条命令出片
ffmpeg·ai编程·claude·电商·agent skills