Windows设备信息获取:(摄像头,声卡为例)Qt,WindowsAPI对比说明(2)
Windows設(shè)備信息獲取:(攝像頭,聲卡為例)Qt,WindowsAPI對比說明
- 補(bǔ)充說明
- 問題
- QT攝像頭相關(guān)信息獲取(分辨率,圖像格式)
- WindowsAPI,win10,win7不兼容問題
- 兼容代碼
- 解決方案
- 其他相關(guān)
補(bǔ)充說明
在上一篇文檔中,文檔末尾提到了,win10,win7兼容問題,QCamera未發(fā)現(xiàn)的問題,這里都做一下說明。
問題
- QCameraInfo問題
在QAudioDeviceInfo中,DeviceName()直接打印,即
打印結(jié)果。
InputDeviceName: "立體聲混音 (Realtek High Definition Audio)"在QCamerInfo中,打印結(jié)果如下
QList<QCameraInfo> cameras = QCameraInfo::availableCameras(); foreach(const QCameraInfo &cameraInfo, cameras) {qDebug() << "CameraInfo:-deviceName()" <<cameraInfo.deviceName();}打印的是設(shè)備路徑,不是我們想要的設(shè)備名稱,后來我去看官方文檔說明:
CameraInfo:-deviceName() "@device:pnp:\\\\?\\usb#vid_046d&pid_0843&mi_00#6&86ea809&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\\global"說明如下:
返回的是攝像頭的驅(qū)動名稱,這是唯一的機(jī)器可識別的ID號,和是人類不能識別的。
后來繼續(xù)看文檔,看到一個這函數(shù)
description(),返回的是人類可識別的描述。
后將幾個函數(shù)打印出來看。
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();}打印結(jié)果如下:
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(),說到,這個函數(shù),返回音頻驅(qū)動,人類可識別的名稱。
QT攝像頭相關(guān)信息獲取(分辨率,圖像格式)
捎帶,又看了一下其他函數(shù)。
攝像頭驅(qū)動名稱已經(jīng)拿到,還有攝像頭支持圖像格式,分辨率
函數(shù)如下:
相關(guān)功能函數(shù):
注意使用時,先打開攝像頭,并且攝像頭打開成功,才能獲取到這些信息。
其他函數(shù)還有。
QList<FrameRateRange> QCamera::supportedViewfinderFrameRateRanges(const QCameraViewfinderSettings &settings = QCameraViewfinderSettings()) const QList<QCameraViewfinderSettings> QCamera::supportedViewfinderSettings(const QCameraViewfinderSettings &settings = QCameraViewfinderSettings()) constWindowsAPI,win10,win7不兼容問題
HID,調(diào)用的時候,打印發(fā)現(xiàn)
Win10下,攝像頭類為
Win7下,攝像頭類為
Image所以函數(shù)在識別的判斷的時候,判斷不到。
音頻類同理,
QT庫,我在win10下安裝,編譯的,在Win7下使用不了,同理。在調(diào)用windows底層API時,判斷條件不一樣,所以不兼容。
GUID,屬性,隨后測試結(jié)果給說明。
兼容代碼
隨后,寫好之后貼上來。
/****更新/
解決方案并不是代碼原因而是一些依賴庫的的問題,詳細(xì)解決方案見下文。
解決方案
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簡單的說,因?yàn)闆]有配置系統(tǒng)變量,所以需要進(jìn)入 windeployqt.exe所在目錄下,即
cd C:\Qt\Qt5.8.0\5.8\msvc2013\bin打包命令如下:
windeployqt <path-to-app-binary>即,你需要打包的exe全路徑
windeployqt /path/file.exe運(yùn)行結(jié)果,如下
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...打包完的目錄結(jié)構(gòu)如下。
即可打包完成,不兼容問題,就這樣解決了。
其他相關(guān)
從目錄結(jié)構(gòu)上來看,可能其他系統(tǒng)不兼容的問題,是由于,audio,mediaservice,imageformats,playlistformats幾個目錄下的文件缺失導(dǎo)致的。
建議,也算個人經(jīng)驗(yàn)吧,以后打包Qt可執(zhí)行程序時盡量使用官方打包軟件。
總結(jié)
以上是生活随笔為你收集整理的Windows设备信息获取:(摄像头,声卡为例)Qt,WindowsAPI对比说明(2)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何运用Microsoft Office
- 下一篇: JavaScript获取浏览器可视区域的