Windows设备信息获取:(摄像头,声卡为例)Qt,WindowsAPI对比说明

  • 补充说明
    • 问题
    • QT摄像头相关信息获取(分辨率,图像格式)
    • WindowsAPI,win10,win7不兼容问题
    • 兼容代码
    • 解决方案
    • 其他相关

补充说明

在上一篇文档中,文档末尾提到了,win10,win7兼容问题,QCamera未发现的问题,这里都做一下说明。

问题

  • QCameraInfo问题
    在QAudioDeviceInfo中,DeviceName()直接打印,即
foreach(const QAudioDeviceInfo &deviveInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioInput)){qDebug() << "InputDeviceName:" << deviveInfo.deviceName();}

打印结果。

InputDeviceName: "立体声混音 (Realtek High Definition Audio)"

在QCamerInfo中,打印结果如下

QList<QCameraInfo> cameras = QCameraInfo::availableCameras();   foreach(const QCameraInfo &cameraInfo, cameras) {qDebug() << "CameraInfo:-deviceName()" <<cameraInfo.deviceName();}

打印的是设备路径,不是我们想要的设备名称,后来我去看官方文档说明:

CameraInfo:-deviceName() "@device:pnp:\\\\?\\usb#vid_046d&pid_0843&mi_00#6&86ea809&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\\global"

说明如下:
返回的是摄像头的驱动名称,这是唯一的机器可识别的ID号,和是人类不能识别的。

**QString QCameraInfo::deviceName() const**Returns the device name of the camera
This is a unique ID to identify the camera and may not be human-readable.

后来继续看文档,看到一个这函数
description(),返回的是人类可识别的描述。

QString QCameraInfo::description() const
Returns the human-readable description of the camera.

后将几个函数打印出来看。

QList<QCameraInfo> cameras = QCameraInfo::availableCameras();   foreach(const QCameraInfo &cameraInfo, cameras) {qDebug() << "CameraInfo:-description()" << cameraInfo.description();qDebug() << "CameraInfo:-deviceName()" <<cameraInfo.deviceName();qDebug() << "CameraInfo:-defaultCamera()" <<cameraInfo.defaultCamera();}

打印结果如下:

  CameraInfo:-description() "Logitech Webcam C930e"CameraInfo:-deviceName() "@device:pnp:\\\\?\\usb#vid_046d&pid_0843&mi_00#6&86ea809&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\\global"CameraInfo:-defaultCamera()  "QCameraInfo(deviceName=@device:pnp:\\\\?\\usb#vid_046d&pid_0843&mi_00#6&86ea809&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\\global, position=UnspecifiedPosition, orientation=0)"

我然后去查看了一下QAudioDeviceInfo的文档说明
QAudioDeviceInfo::deviceName(),说到,这个函数,返回音频驱动,人类可识别的名称。

QString QAudioDeviceInfo::deviceName() const
Returns the human readable name of the audio device.
Device names vary depending on the platform/audio plugin being used.
They are a unique string identifier for the audio device.
eg. default, Intel, U0x46d0x9a4

QT摄像头相关信息获取(分辨率,图像格式)

捎带,又看了一下其他函数。
摄像头驱动名称已经拿到,还有摄像头支持图像格式,分辨率
函数如下:

    QList<QSize> mResSize = {};//分辨率List 定义QList<QCameraInfo> cameras = QCameraInfo::availableCameras();   foreach(const QCameraInfo &cameraInfo, cameras) {qDebug() << "CameraInfo:-description()" << cameraInfo.description();QCamera mCamera(cameraInfo);mCamera.start();QList<QVideoFrame::PixelFormat> mList = mCamera.supportedViewfinderPixelFormats();//图像格式mResSize = mCamera.supportedViewfinderResolutions();foreach (QSize msize, mResSize) {qDebug()<<msize;}  //摄像头支持分辨率打印qDebug()<<mList[0]<<mList[1];mCamera.stop();}
Format_YUYV Format_Jpeg //图像格式
//分辨率如下
QSize(160, 120)
QSize(176, 144)
QSize(320, 180)
QSize(320, 240)
QSize(352, 288)
QSize(424, 240)
QSize(480, 270)
QSize(640, 360)
QSize(640, 480)
QSize(800, 448)
QSize(848, 480)
QSize(800, 600)
QSize(960, 540)
QSize(1024, 576)
QSize(1280, 720)
QSize(1600, 896)
QSize(1920, 1080)
QSize(2304, 1296)
QSize(2304, 1536)

相关功能函数:
注意使用时,先打开摄像头,并且摄像头打开成功,才能获取到这些信息。

QList<QSize> QCamera::supportedViewfinderResolutions(const QCameraViewfinderSettings &settings = QCameraViewfinderSettings()) const
QList<QVideoFrame::PixelFormat> QCamera::supportedViewfinderPixelFormats(const QCameraViewfinderSettings &settings = QCameraViewfinderSettings()) const

其他函数还有。

QList<FrameRateRange> QCamera::supportedViewfinderFrameRateRanges(const QCameraViewfinderSettings &settings = QCameraViewfinderSettings()) const
QList<QCameraViewfinderSettings> QCamera::supportedViewfinderSettings(const QCameraViewfinderSettings &settings = QCameraViewfinderSettings()) const

WindowsAPI,win10,win7不兼容问题

HID,调用的时候,打印发现
Win10下,摄像头类为

Camera

Win7下,摄像头类为

Image

所以函数在识别的判断的时候,判断不到。
音频类同理,
QT库,我在win10下安装,编译的,在Win7下使用不了,同理。在调用windows底层API时,判断条件不一样,所以不兼容。
GUID,属性,随后测试结果给说明。

兼容代码

随后,写好之后贴上来。
/****更新/
解决方案并不是代码原因而是一些依赖库的的问题,详细解决方案见下文。

解决方案

Qt 有一个官方打包依赖库文件的工具,windeployqt.exe,在 Qt bin 目录下,以我的为例。

C:\Qt\Qt5.8.0\5.8\msvc2013\bin

使用方法。

C:\Qt\Qt5.8.0\5.8\msvc2013\bin>windeployqt -h
Usage: windeployqt [options] [files]
Qt Deploy Tool 5.8.0The simplest way to use windeployqt is to add the bin directory of your Qt
installation (e.g. <QT_DIR\bin>) to the PATH variable and then run:windeployqt <path-to-app-binary>
If ICU, ANGLE, etc. are not in the bin directory, they need to be in the PATH
variable. If your application uses Qt Quick, run:windeployqt --qmldir <path-to-app-qml-files> <path-to-app-binary>Options:-?, -h, --help            Displays this help.-v, --version             Displays version information.--dir <directory>         Use directory instead of binary directory.--libdir <path>           Copy libraries to path.--plugindir <path>        Copy plugins to path.--debug                   Assume debug binaries.--release                 Assume release binaries.--pdb                     Deploy .pdb files (MSVC).--force                   Force updating files.--dry-run                 Simulation mode. Behave normally, but do notcopy/update any files.--no-plugins              Skip plugin deployment.--no-libraries            Skip library deployment.--qmldir <directory>      Scan for QML-imports starting from directory.--no-quick-import         Skip deployment of Qt Quick imports.--no-translations         Skip deployment of translations.--no-system-d3d-compiler  Skip deployment of the system D3D compiler.--compiler-runtime        Deploy compiler runtime (Desktop only).--no-compiler-runtime     Do not deploy compiler runtime (Desktop only).--webkit2                 Deployment of WebKit2 (web process).--no-webkit2              Skip deployment of WebKit2.--json                    Print to stdout in JSON format.--angle                   Force deployment of ANGLE.--no-angle                Disable deployment of ANGLE.--no-opengl-sw            Do not deploy the software rasterizer library.--list <option>           Print only the names of the files copied.Available options:source:   absolute path of the source filestarget:   absolute path of the target filesrelative: paths of the target files, relativeto the target directorymapping:  outputs the source and the relativetarget, suitable for use within anAppx mapping file--verbose <level>         Verbose level.Qt libraries can be added by passing their name (-xml) or removed by passing
the name prepended by --no- (--no-xml). Available libraries:
bluetooth clucene concurrent core declarative designer designercomponents
enginio gui qthelp multimedia multimediawidgets multimediaquick network nfc
opengl positioning printsupport qml qmltooling quick quickparticles quickwidgets
script scripttools sensors serialport sql svg test webkit webkitwidgets
websockets widgets winextras xml xmlpatterns webenginecore webengine
webenginewidgets 3dcore 3drenderer 3dquick 3dquickrenderer 3dinput geoservices
webchannel texttospeech serialbus

简单的说,因为没有配置系统变量,所以需要进入 windeployqt.exe所在目录下,即

cd C:\Qt\Qt5.8.0\5.8\msvc2013\bin

打包命令如下:

windeployqt <path-to-app-binary>

即,你需要打包的exe全路径

windeployqt  /path/file.exe

运行结果,如下

C:\Qt\Qt5.8.0\5.8\msvc2013\bin>windeployqt E:\9-Pccamer\DesConsole\build-DesConsole-Desktop_Qt_5_8_0_MSVC2013_32bit-Debug\debug\app\file.exe
E:\9-Pccamer\DesConsole\build-DesConsole-Desktop_Qt_5_8_0_MSVC2013_32bit-Debug\debug\app\PCCamer.exe 32 bit, debug executable
Adding Qt5Svg for qsvgicond.dll
Skipping plugin qtvirtualkeyboardplugind.dll due to disabled dependencies.
Direct dependencies: Qt5Core Qt5Multimedia Qt5Widgets
All dependencies   : Qt5Core Qt5Gui Qt5Multimedia Qt5Network Qt5Widgets
To be deployed     : Qt5Core Qt5Gui Qt5Multimedia Qt5Network Qt5Svg Qt5Widgets
Warning: Cannot find Visual Studio installation directory, VCINSTALLDIR is not set.
Updating Qt5Cored.dll.
Updating Qt5Guid.dll.
Updating Qt5Multimediad.dll.
Updating Qt5Networkd.dll.
Updating Qt5Svgd.dll.
Updating Qt5Widgetsd.dll.
Updating libGLESV2d.dll.
Updating libEGLd.dll.
Updating D3Dcompiler_47.dll.
Updating opengl32sw.dll.
Patching Qt5Cored.dll...
Creating directory E:/9-Pccamer/DesConsole/build-DesConsole-Desktop_Qt_5_8_0_MSVC2013_32bit-Debug/debug/app/audio.
Updating qtaudio_windowsd.dll.
Creating directory E:/9-Pccamer/DesConsole/build-DesConsole-Desktop_Qt_5_8_0_MSVC2013_32bit-Debug/debug/app/bearer.
Updating qgenericbearerd.dll.
Updating qnativewifibearerd.dll.
Creating directory E:/9-Pccamer/DesConsole/build-DesConsole-Desktop_Qt_5_8_0_MSVC2013_32bit-Debug/debug/app/iconengines.
Updating qsvgicond.dll.
Creating directory E:/9-Pccamer/DesConsole/build-DesConsole-Desktop_Qt_5_8_0_MSVC2013_32bit-Debug/debug/app/imageformats.
Updating qgifd.dll.
Updating qicnsd.dll.
Updating qicod.dll.
Updating qjpegd.dll.
Updating qsvgd.dll.
Updating qtgad.dll.
Updating qtiffd.dll.
Updating qwbmpd.dll.
Updating qwebpd.dll.
Creating directory E:/9-Pccamer/DesConsole/build-DesConsole-Desktop_Qt_5_8_0_MSVC2013_32bit-Debug/debug/app/mediaservice.
Updating dsengined.dll.
Updating qtmedia_audioengined.dll.
Updating wmfengined.dll.
Creating directory E:/9-Pccamer/DesConsole/build-DesConsole-Desktop_Qt_5_8_0_MSVC2013_32bit-Debug/debug/app/platforms.
Updating qwindowsd.dll.
Creating directory E:/9-Pccamer/DesConsole/build-DesConsole-Desktop_Qt_5_8_0_MSVC2013_32bit-Debug/debug/app/playlistformats.
Updating qtmultimedia_m3ud.dll.
Creating E:\9-Pccamer\DesConsole\build-DesConsole-Desktop_Qt_5_8_0_MSVC2013_32bit-Debug\debug\app\translations...
Creating qt_ca.qm...
Creating qt_cs.qm...
Creating qt_de.qm...
Creating qt_en.qm...
Creating qt_fi.qm...
Creating qt_fr.qm...
Creating qt_he.qm...
Creating qt_hu.qm...
Creating qt_it.qm...
Creating qt_ja.qm...
Creating qt_ko.qm...
Creating qt_lv.qm...
Creating qt_pl.qm...
Creating qt_ru.qm...
Creating qt_sk.qm...
Creating qt_uk.qm...

打包完的目录结构如下。

即可打包完成,不兼容问题,就这样解决了。

其他相关

从目录结构上来看,可能其他系统不兼容的问题,是由于,audio,mediaservice,imageformats,playlistformats几个目录下的文件缺失导致的。
建议,也算个人经验吧,以后打包Qt可执行程序时尽量使用官方打包软件。

Windows设备信息获取:(摄像头,声卡为例)Qt,WindowsAPI对比说明(2)相关推荐

  1. Android 手机设备信息获取使用详解

    Android 手机是我们常用的工具之一,买手机之前,手机厂商会提供一些手机参数给我们,那么问题来了,我们该如何获取手机上的参数信息呢? 通过本文你讲了解到获取手机常用信息的基本方法. 获取手机基本信 ...

  2. iOS: iOS各种设备信息获取

    Author:si1ence Link:http://www.jianshu.com/p/b23016bb97af 为了统计用户信息.下发广告,服务器端往往需要手机用户设备及app的各种信息,下面讲述 ...

  3. 史上最全的iOS各种设备信息获取总结(iPhone X 详细信息已更新)

    2016.07.01 更新至iPhone X 新增设备颜色的获取 为了统计用户信息.下发广告,服务器端往往需要手机用户设备及app的各种信息,下面讲述一下各种信息的获取方式: 点击下载以上展示效果的G ...

  4. 苹果设备信息获取(截止到2016-02-23)

    为什么80%的码农都做不了架构师?>>>    切记 导入头文件哦 .h #import "sys/utsname.h" + (NSString *)getCur ...

  5. 史上最全的iOS各种设备信息获取总结(iPhone8/iPhone X 已更新)

    不管是在Android开发还是iOS开发过程中,有时候我们需要经常根据设备的一些状态或信息进行不同的设置和性能配置,例如横竖屏切换时,电池电量低时,内存不够时,网络切换时等等,我们在这时候需要进行一些 ...

  6. 史上最全的iOS各种设备信息获取总结(iPhone 12已更新)

    更新至iPhone 11   [转] 添加了iphone12的设备 > 为了统计用户信息.下发广告,服务器端往往需要手机用户设备及app的各种信息,下面讲述一下各种信息的获取方式: ![imag ...

  7. android获取ro._Android 简单的设备信息获取

    在用python写自动化测试脚本的脚本的时候通常回需要获取一些android设备的硬件信息.网上给的很多方案都是通常通过/system/build.prop中去获取,但是回遇到permission d ...

  8. Android设备信息获取

    近个多月之前整理的,记录,共享. 1)android 获取设备型号.OS版本号: import android.os.Build; // ..... Build bd = new Build(); S ...

  9. 史上最全的iOS各种设备信息获取总结

    http://www.cocoachina.com/ios/20171024/20890.html 为了统计用户信息.下发广告,服务器端往往需要手机用户设备及app的各种信息,下面讲述一下各种信息的获 ...

最新文章

  1. Linux从入门到精通系列之SHELL编程循环语句语法及实例详解(forwhileuntil)
  2. 利用叉乘快速判断点是否在三角形内
  3. mysql语句表_mysql表级sql语句
  4. 面试官:DDD如何指导微服务拆分?90%的程序员都答不上来!
  5. 单片机原理及其应用——单片机定时器中断实验(八段数码管依次显示0~9数字)
  6. Swift - 从字典(或者Alamofire)直接创建Model文件的工具
  7. vue组件通信大总结
  8. 关于 width;height
  9. 最快理解使用CSS弹性盒子
  10. linux shell读取文件,shell脚本中读取文件的方法
  11. base64的原理及优缺点
  12. windows批量ping测试脚本
  13. Android短信发送,监听,及其工具类封装
  14. 思迈特软件Smartbi:公安大数据的3个发展阶段
  15. Ant Design vue v-decorate 进行数据绑定
  16. 2. 工业大数据的特点
  17. Win10系统耳机插入不起作用_依然外放声音---Windows运维工作笔记053
  18. 崩坏3九游服务器稳定吗,崩坏3:大佬亲身经历告诉你,玩崩坏3到底该不该压等级!...
  19. 2015年年终总结学习篇:为了梦想不服输,再苦也不能停止脚步
  20. 哈罗单车再获10亿融资,摩拜、ofo难合并!

热门文章

  1. matlab里面sin函数是角度,matlab-如何用matlab编写sin函数要求定义一 – 手机爱问
  2. blas、lapack、atlas在Ubuntu上的安装
  3. VsCode镜像下载(国内镜像源,高速秒下)
  4. CoreOS容器云企业实战(3)--Docker技术实践
  5. 美国网站直接shopping之经验总结
  6. Android攻城狮 Handler与子线程
  7. 《攻城Online》快速原型:服务端设计
  8. 智能ALMP封装推拉力测试机 剪切力强度测试仪器主要功能介绍
  9. PNG图片压缩原理--屌丝的眼泪 #1
  10. json rpgmv 加密_加密-如何对JSON对象进行加密哈希处理?