{"id":109023,"date":"2026-09-23T07:56:54","date_gmt":"2026-09-22T23:56:54","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/109023.html"},"modified":"2026-09-23T07:56:54","modified_gmt":"2026-09-22T23:56:54","slug":"%e3%80%90qt%e3%80%91%e3%80%8aqt-5-9-c%e5%bc%80%e5%8f%91%e6%8c%87%e5%8d%97%e3%80%8b%e7%ac%94%e8%ae%b0-chapter15-%e5%a4%9a%e5%aa%92%e4%bd%93","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/109023.html","title":{"rendered":"\u3010Qt\u3011\u300aQt 5.9 C++\u5f00\u53d1\u6307\u5357\u300b\u7b14\u8bb0-Chapter15-\u591a\u5a92\u4f53"},"content":{"rendered":"<h2>\u7b2c15\u7ae0\u3000\u591a\u5a92\u4f53<\/h2>\n<p>\u591a\u5a92\u4f53\u529f\u80fd\u6307\u7684\u4e3b\u8981\u662f\u8ba1\u7b97\u673a\u7684\u97f3\u9891\u548c\u89c6\u9891\u7684\u8f93\u5165\u3001\u8f93\u51fa\u3001\u663e\u793a\u548c\u64ad\u653e\u7b49\u529f\u80fd&#xff0c;Qt\u7684\u591a\u5a92\u4f53\u6a21\u5757\u4e3a\u97f3\u9891\u548c\u89c6\u9891\u64ad\u653e\u3001\u5f55\u97f3\u3001\u6444\u50cf\u5934\u62cd\u7167\u548c\u5f55\u50cf\u7b49\u63d0\u4f9b\u652f\u6301&#xff0c;\u751a\u81f3\u8fd8\u63d0\u4f9b\u6570\u5b57\u6536\u97f3\u673a\u7684\u652f\u6301\u3002\u672c\u7ae0\u5c06\u4ecb\u7ecdQt\u591a\u5a92\u4f53\u6a21\u5757\u7684\u529f\u80fd\u548c\u4f7f\u7528\u3002<\/p>\n<h3>15.1\u3000Qt\u591a\u5a92\u4f53\u6a21\u5757\u529f\u80fd\u6982\u8ff0<\/h3>\n<p>Qt\u591a\u5a92\u4f53\u6a21\u5757\u63d0\u4f9b\u4e86\u5f88\u591a\u7c7b&#xff0c;\u53ef\u4ee5\u5b9e\u73b0\u5982\u4e0b\u7684\u4e00\u4e9b\u529f\u80fd&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u8bbf\u95ee\u539f\u59cb\u97f3\u9891\u8bbe\u5907\u8fdb\u884c\u8f93\u5165\u6216\u8f93\u51fa&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u4f4e\u5ef6\u8fdf\u64ad\u653e\u97f3\u6548\u6587\u4ef6&#xff0c;\u5982WAV\u6587\u4ef6&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528\u64ad\u653e\u5217\u8868\u64ad\u653e\u538b\u7f29\u7684\u97f3\u9891\u548c\u89c6\u9891\u6587\u4ef6&#xff0c;\u5982mp3\u3001wmv\u7b49&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u5f55\u5236\u58f0\u97f3\u5e76\u4e14\u538b\u5236\u6587\u4ef6&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528\u6444\u50cf\u5934\u8fdb\u884c\u9884\u89c8\u3001\u62cd\u7167\u548c\u89c6\u9891\u5f55\u5236&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u97f3\u9891\u6587\u4ef6\u89e3\u7801\u5230\u5185\u5b58\u8fdb\u884c\u5904\u7406&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u5f55\u5236\u97f3\u9891\u6216\u89c6\u9891\u65f6&#xff0c;\u8bbf\u95ee\u5176\u89c6\u9891\u5e27\u6216\u97f3\u9891\u7f13\u51b2\u533a&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u6570\u5b57\u5e7f\u64ad\u8c03\u8c10\u548c\u6536\u542c\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u8981\u5728C&#043;&#043;\u9879\u76ee\u4e2d\u4f7f\u7528Qt\u591a\u5a92\u4f53\u6a21\u5757&#xff0c;\u9700\u8981\u5728\u9879\u76ee\u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0\u5982\u4e0b\u4e00\u884c\u8bed\u53e5&#xff1a;<\/p>\n<p>Qt &#043;&#061; multimedia<\/p>\n<p>\u5982\u679c\u5728\u9879\u76ee\u4e2d\u4f7f\u7528\u89c6\u9891\u64ad\u653e\u529f\u80fd&#xff0c;\u8fd8\u9700\u8981\u52a0\u5165\u4e0b\u9762\u7684\u4e00\u884c&#xff0c;\u4ee5\u4f7f\u7528QVideoWidget\u6216QGraphicsVideoItem\u8fdb\u884c\u89c6\u9891\u64ad\u653e\u3002<\/p>\n<p>Qt &#043;&#061; multimediawidgets<\/p>\n<p>Qt\u591a\u5a92\u4f53\u6a21\u5757\u5305\u62ec\u591a\u4e2a\u7c7b&#xff0c;\u886815-1\u662f\u4e00\u4e9b\u5178\u578b\u7684\u591a\u5a92\u4f53\u5e94\u7528\u6240\u9700\u8981\u7528\u5230\u7684\u4e3b\u8981\u7684\u7c7b\u3002<\/p>\n<p>\u886815-1\u3000\u5404\u7c7b\u591a\u5a92\u4f53\u529f\u80fd\u7528\u5230\u7684\u7c7b<\/p>\n<table>\n<tr>\u5e94\u7528\u529f\u80fd\u7528\u5230\u7684\u7c7b<\/tr>\n<tbody>\n<tr>\n<td>\u64ad\u653e\u538b\u7f29\u97f3\u9891&#xff08;MP3\u3001AAC\u7b49&#xff09;<\/td>\n<td>QMediaPlayer&#xff0c;QMediaPlaylist<\/td>\n<\/tr>\n<tr>\n<td>\u64ad\u653e\u97f3\u6548\u6587\u4ef6&#xff08;WAV\u6587\u4ef6&#xff09;<\/td>\n<td>QSoundEffect&#xff0c;QSound<\/td>\n<\/tr>\n<tr>\n<td>\u64ad\u653e\u4f4e\u5ef6\u8fdf\u7684\u97f3\u9891<\/td>\n<td>QAudioOutput<\/td>\n<\/tr>\n<tr>\n<td>\u8bbf\u95ee\u539f\u59cb\u97f3\u9891\u8f93\u5165\u6570\u636e<\/td>\n<td>QAudioInput<\/td>\n<\/tr>\n<tr>\n<td>\u5f55\u5236\u7f16\u7801\u7684\u97f3\u9891\u6570\u636e<\/td>\n<td>QAudioRecorder<\/td>\n<\/tr>\n<tr>\n<td>\u53d1\u73b0\u97f3\u9891\u8bbe\u5907<\/td>\n<td>QAudioDeviceInfo<\/td>\n<\/tr>\n<tr>\n<td>\u89c6\u9891\u64ad\u653e<\/td>\n<td>QMediaPlayer&#xff0c;QVideoWidget&#xff0c;QGraphicsVideoItem<\/td>\n<\/tr>\n<tr>\n<td>\u89c6\u9891\u5904\u7406<\/td>\n<td>QMediaPlayer&#xff0c;QVideoFrame&#xff0c;QAbstractVideoSurface<\/td>\n<\/tr>\n<tr>\n<td>\u6444\u50cf\u5934\u53d6\u666f\u6846<\/td>\n<td>QCamera&#xff0c;QVideoWidget&#xff0c;QGraphicsVideoItem<\/td>\n<\/tr>\n<tr>\n<td>\u53d6\u666f\u6846\u9884\u89c8\u5904\u7406<\/td>\n<td>QCamera&#xff0c;QAbstractVideoSurface&#xff0c;QVideoFrame<\/td>\n<\/tr>\n<tr>\n<td>\u6444\u50cf\u5934\u62cd\u7167<\/td>\n<td>QCamera&#xff0c;QCameraImageCapture<\/td>\n<\/tr>\n<tr>\n<td>\u6444\u50cf\u5934\u5f55\u50cf<\/td>\n<td>QCamera&#xff0c;QMediaRecorder<\/td>\n<\/tr>\n<tr>\n<td>\u6536\u542c\u6570\u5b57\u5e7f\u64ad<\/td>\n<td>QRadioTuner&#xff0c;QRadioData<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5229\u7528Qt\u591a\u5a92\u4f53\u6a21\u5757\u63d0\u4f9b\u7684\u5404\u79cd\u7c7b&#xff0c;\u53ef\u4ee5\u5b9e\u73b0\u4e00\u822c\u7684\u97f3\u9891\u3001\u89c6\u9891\u7684\u8f93\u5165\u548c\u8f93\u51fa\u3002\u8fd9\u5728\u4e00\u4e9b\u5b9e\u9645\u5e94\u7528\u4e2d\u662f\u9700\u8981\u7684&#xff0c;\u5982\u8bed\u97f3\u8bc6\u522b\u9700\u8981\u5f55\u5236\u97f3\u9891\u5e76\u5bf9\u97f3\u9891\u6570\u636e\u8fdb\u884c\u5904\u7406&#xff0c;\u8f66\u724c\u81ea\u52a8\u8bc6\u522b\u9700\u8981\u5148\u62cd\u7167\u7136\u540e\u8fdb\u884c\u56fe\u50cf\u5904\u7406\u3002<\/p>\n<p>\u672c\u7ae0\u5c06\u4ecb\u7ecd\u97f3\u9891\u7684\u64ad\u653e\u548c\u5f55\u5236\u3001\u89c6\u9891\u64ad\u653e\u3001\u6444\u50cf\u5934\u62cd\u7167\u4e0e\u5f55\u50cf\u7b49\u529f\u80fd\u7684\u5b9e\u73b0\u3002\u6570\u5b57\u5e7f\u64ad\u9700\u8981\u5177\u6709\u6570\u5b57\u8c03\u9891\u529f\u80fd\u7684\u786c\u4ef6\u8bbe\u5907&#xff0c;\u4e00\u822c\u7528\u6237\u6ca1\u6709\u8fd9\u6837\u7684\u786c\u4ef6\u8bbe\u5907&#xff0c;\u672c\u4e66\u5c31\u4e0d\u4e88\u4ecb\u7ecd\u4e86\u3002<\/p>\n<h3>15.2\u3000\u97f3\u9891\u64ad\u653e<\/h3>\n<h4>15.2.1\u3000\u4f7f\u7528QMediaPlayer\u64ad\u653e\u97f3\u4e50\u6587\u4ef6<\/h4>\n<h5>1&#xff0e;\u97f3\u9891\u64ad\u653e\u5668\u5b9e\u4f8b\u7a0b\u5e8f<\/h5>\n<p>QMediaPlayer\u53ef\u4ee5\u64ad\u653e\u7ecf\u8fc7\u538b\u7f29\u7684\u97f3\u9891\u6216\u89c6\u9891\u6587\u4ef6&#xff0c;\u5982mp3\u3001mp4\u3001wmv\u7b49\u6587\u4ef6&#xff0c;QMediaPlayer\u53ef\u4ee5\u64ad\u653e\u5355\u4e2a\u6587\u4ef6&#xff0c;\u4e5f\u53ef\u4ee5\u548cQMediaPlaylist\u7c7b\u7ed3\u5408&#xff0c;\u5bf9\u4e00\u4e2a\u64ad\u653e\u5217\u8868\u8fdb\u884c\u64ad\u653e\u3002\u6240\u4ee5\u4f7f\u7528QMediaPlayer\u548cQMediaPlaylist\u53ef\u4ee5\u8f7b\u677e\u5730\u8bbe\u8ba1\u4e00\u4e2a\u81ea\u5df1\u7684\u97f3\u4e50\u6216\u89c6\u9891\u64ad\u653e\u5668\u3002<\/p>\n<p>QMediaPlayer\u7684\u4e3b\u8981\u516c\u5171\u51fd\u6570\u548c\u69fd\u51fd\u6570\u89c1\u886815-2&#xff08;\u7701\u7565\u4e86\u51fd\u6570\u4e2d\u7684const\u5173\u952e\u5b57\u548c\u7f3a\u7701\u53c2\u6570&#xff09;\u3002<\/p>\n<p>\u886815-2\u3000QMediaPlayer\u7684\u4e3b\u8981\u51fd\u6570<\/p>\n<table>\n<tr>\u51fd\u6570\u539f\u578b\u529f\u80fd\u63cf\u8ff0<\/tr>\n<tbody>\n<tr>\n<td>qint64\u3000duration()<\/td>\n<td>\u5f53\u524d\u6587\u4ef6\u64ad\u653e\u65f6\u95f4\u603b\u957f&#xff0c;\u5355\u4f4dms<\/td>\n<\/tr>\n<tr>\n<td>void\u3000setPosition(qint64 position)<\/td>\n<td>\u8bbe\u7f6e\u5f53\u524d\u6587\u4ef6\u64ad\u653e\u4f4d\u7f6e&#xff0c;\u5355\u4f4dms<\/td>\n<\/tr>\n<tr>\n<td>void\u3000setMuted(bool muted)<\/td>\n<td>\u8bbe\u7f6e\u662f\u5426\u9759\u97f3<\/td>\n<\/tr>\n<tr>\n<td>bool\u3000isMuted()<\/td>\n<td>\u8fd4\u56de\u662f\u5426\u9759\u97f3\u7684\u72b6\u6001&#xff0c;true\u8868\u793a\u9759\u97f3<\/td>\n<\/tr>\n<tr>\n<td>void\u3000setPlaylist(QMediaPlaylist *playlist)<\/td>\n<td>\u8bbe\u7f6e\u64ad\u653e\u5217\u8868<\/td>\n<\/tr>\n<tr>\n<td>QMediaPlaylist*\u3000playlist()<\/td>\n<td>\u8fd4\u56de\u8bbe\u7f6e\u7684\u64ad\u653e\u5217\u8868<\/td>\n<\/tr>\n<tr>\n<td>State\u3000state()<\/td>\n<td>\u8fd4\u56de\u64ad\u653e\u5668\u5f53\u524d\u7684\u72b6\u6001<\/td>\n<\/tr>\n<tr>\n<td>void\u3000setVolume(int volume)<\/td>\n<td>\u8bbe\u7f6e\u64ad\u653e\u97f3\u91cf&#xff0c;0\u81f3100\u4e4b\u95f4<\/td>\n<\/tr>\n<tr>\n<td>void\u3000setPlaybackRate(qreal rate)<\/td>\n<td>\u8bbe\u7f6e\u64ad\u653e\u901f\u5ea6&#xff0c;\u7f3a\u7701\u4e3a1&#xff0c;\u8868\u793a\u6b63\u5e38\u901f\u5ea6<\/td>\n<\/tr>\n<tr>\n<td>void\u3000setMedia(QMediaContent &amp;media)<\/td>\n<td>\u8bbe\u7f6e\u64ad\u653e\u5a92\u4f53\u6587\u4ef6<\/td>\n<\/tr>\n<tr>\n<td>QMediaContent\u3000currentMedia()<\/td>\n<td>\u8fd4\u56de\u5f53\u524d\u64ad\u653e\u7684\u5a92\u4f53\u6587\u4ef6<\/td>\n<\/tr>\n<tr>\n<td>void\u3000play()<\/td>\n<td>\u5f00\u59cb\u64ad\u653e<\/td>\n<\/tr>\n<tr>\n<td>void\u3000pause()<\/td>\n<td>\u6682\u505c\u64ad\u653e<\/td>\n<\/tr>\n<tr>\n<td>void\u3000stop()<\/td>\n<td>\u505c\u6b62\u64ad\u653e<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4f7f\u7528QMediaPlayer\u64ad\u653e\u5a92\u4f53\u6587\u4ef6\u65f6&#xff0c;\u6709\u51e0\u4e2a\u6709\u7528\u7684\u4fe1\u53f7\u53ef\u4ee5\u53cd\u6620\u64ad\u653e\u72b6\u6001\u6216\u6587\u4ef6\u4fe1\u606f\u3002<\/p>\n<ul>\n<li>stateChanged(QMediaPlayer::State state)\u4fe1\u53f7\u5728\u8c03\u7528play()\u3001pause()\u548cstop()\u51fd\u6570\u65f6\u53d1\u5c04&#xff0c;\u53cd\u6620\u64ad\u653e\u5668\u5f53\u524d\u7684\u72b6\u6001\u3002\u679a\u4e3e\u7c7b\u578bQMediaPlayer::State\u67093\u79cd\u53d6\u503c&#xff0c;\u8868\u793a\u64ad\u653e\u5668\u7684\u72b6\u6001&#xff1a;<\/li>\n<\/ul>\n<p>QMediaPlayer::StoppedState&#xff0c;\u505c\u6b62\u72b6\u6001&#xff1b;<\/p>\n<p>QMediaPlayer::PlayingState&#xff0c;\u6b63\u5728\u64ad\u653e&#xff1b;<\/p>\n<p>QMediaPlayer::PausedState&#xff0c;\u6682\u505c\u64ad\u653e\u72b6\u6001\u3002<\/p>\n<ul>\n<li>\n<p>durationChanged(qint64 duration)\u4fe1\u53f7\u5728\u6587\u4ef6\u7684\u65f6\u95f4\u957f\u5ea6\u53d8\u5316\u65f6\u53d1\u5c04&#xff0c;\u4e00\u822c\u5728\u5207\u6362\u64ad\u653e\u6587\u4ef6\u65f6\u53d1\u5c04\u3002<\/p>\n<\/li>\n<li>\n<p>positionChanged(qint64 position)\u5f53\u524d\u6587\u4ef6\u64ad\u653e\u4f4d\u7f6e\u53d8\u5316\u65f6\u53d1\u5c04&#xff0c;\u53ef\u4ee5\u53cd\u6620\u6587\u4ef6\u64ad\u653e\u8fdb\u5ea6\u3002<\/p>\n<\/li>\n<\/ul>\n<p>QMediaPlayer\u53ef\u4ee5\u901a\u8fc7setMedia()\u51fd\u6570\u8bbe\u7f6e\u64ad\u653e\u5355\u4e2a\u6587\u4ef6&#xff0c;\u4e5f\u53ef\u4ee5\u901a\u8fc7setPlaylist()\u51fd\u6570\u8bbe\u7f6e\u4e00\u4e2aQMediaPlaylist\u7c7b\u5b9e\u4f8b\u8868\u793a\u7684\u64ad\u653e\u5217\u8868&#xff0c;\u5bf9\u5217\u8868\u6587\u4ef6\u8fdb\u884c\u64ad\u653e&#xff0c;\u5e76\u4e14\u81ea\u52a8\u64ad\u653e\u4e0b\u4e00\u4e2a\u6587\u4ef6&#xff0c;\u6216\u5faa\u73af\u64ad\u653e\u7b49\u3002QMediaPlayer\u64ad\u653e\u7684\u6587\u4ef6\u53ef\u4ee5\u662f\u672c\u5730\u6587\u4ef6&#xff0c;\u4e5f\u53ef\u4ee5\u662f\u7f51\u7edc\u4e0a\u7684\u6587\u4ef6\u3002<\/p>\n<p>QMediaPlaylist\u8bb0\u5f55\u64ad\u653e\u5a92\u4f53\u6587\u4ef6\u4fe1\u606f&#xff0c;\u53ef\u4ee5\u6dfb\u52a0\u3001\u79fb\u9664\u6587\u4ef6&#xff0c;\u4e5f\u53ef\u4ee5\u8bbe\u7f6e\u5faa\u73af\u64ad\u653e\u5f62\u5f0f&#xff0c;\u5728\u5217\u8868\u6587\u4ef6\u4e2d\u81ea\u52a8\u5207\u6362\u6587\u4ef6\u3002\u5728\u5f53\u524d\u64ad\u653e\u6587\u4ef6\u5207\u6362\u65f6\u4f1a\u53d1\u5c04currentIndexChanged()\u4fe1\u53f7\u548ccurrentMediaChange()\u4fe1\u53f7\u3002<\/p>\n<p>\u4f7f\u7528QMediaPlayer\u548cQMediaPlaylist\u7684\u8fd9\u4e9b\u529f\u80fd&#xff0c;\u53ef\u4ee5\u5b9e\u73b0\u4e00\u4e2a\u5b8c\u6574\u529f\u80fd\u7684\u97f3\u4e50\u64ad\u653e\u5668\u3002\u539f\u4e66\u7684\u56fe15-1\u662f\u4f7f\u7528QMediaPlayer\u548cQMediaPlaylist\u5b9e\u73b0\u7684\u4e00\u4e2a\u97f3\u4e50\u64ad\u653e\u5668\u5b9e\u4f8b\u7a0b\u5e8fsamp15_1&#xff0c;\u5b83\u5b9e\u73b0\u4e86\u4e00\u4e2a\u97f3\u4e50\u64ad\u653e\u5668\u7684\u57fa\u672c\u529f\u80fd\u3002<\/p>\n<h5>2&#xff0e;\u754c\u9762\u8bbe\u8ba1\u4e0e\u4e3b\u7a97\u53e3\u7c7b\u7684\u5b9a\u4e49<\/h5>\n<p>\u5b9e\u4f8bsamp15_1\u662f\u4e00\u4e2a\u754c\u9762\u57fa\u4e8eQMainWindow\u7684\u5e94\u7528\u7a0b\u5e8f&#xff0c;\u4e3b\u7a97\u53e3\u4e0a\u5220\u9664\u4e86\u83dc\u5355\u680f\u3001\u5de5\u5177\u680f\u548c\u72b6\u6001\u680f&#xff0c;\u754c\u9762\u91c7\u7528UI\u8bbe\u8ba1\u5668\u8bbe\u8ba1&#xff0c;\u4e2d\u95f4\u662f\u4e00\u4e2aQListWidget\u7ec4\u4ef6\u663e\u793a\u64ad\u653e\u5217\u8868\u7684\u6587\u4ef6\u540d\u3002\u5176\u4ed6\u7684\u754c\u9762\u7ec4\u4ef6\u548c\u5e03\u5c40\u8bbe\u8ba1\u4e0d\u518d\u8d58\u8ff0\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4e3b\u7a97\u53e3\u7c7b\u7684\u5b9a\u4e49&#xff08;\u7701\u7565\u4e86UI\u8bbe\u8ba1\u5668\u81ea\u52a8\u751f\u6210\u7684\u754c\u9762\u7ec4\u4ef6\u7684\u69fd\u51fd\u6570&#xff09;&#xff1a;<\/p>\n<p>class MainWindow : public QMainWindow<br \/>\n{<br \/>\n   Q_OBJECT<br \/>\nprivate:<br \/>\n   QMediaPlayer   *player;\/\/\u64ad\u653e\u5668<br \/>\n   QMediaPlaylist  *playlist;\/\/\u64ad\u653e\u5217\u8868<br \/>\n   QString  durationTime;\/\/\u603b\u957f\u5ea6<br \/>\n   QString  positionTime;\/\/\u5f53\u524d\u64ad\u653e\u5230\u7684\u4f4d\u7f6e<br \/>\npublic:<br \/>\n   explicit MainWindow(QWidget *parent &#061; 0);<br \/>\nprivate slots:<br \/>\n\/\/\u81ea\u5b9a\u4e49\u69fd\u51fd\u6570<br \/>\n   void onStateChanged(QMediaPlayer::State state);<br \/>\n   void onPlaylistChanged(int position);<br \/>\n   void onDurationChanged(qint64 duration);<br \/>\n   void onPositionChanged(qint64 position);<br \/>\nprivate:<br \/>\n   Ui::MainWindow *ui;<br \/>\n};<\/p>\n<p>\u4e3b\u8981\u662f\u5b9a\u4e49\u4e864\u4e2a\u79c1\u6709\u53d8\u91cf&#xff0c;4\u4e2a\u81ea\u5b9a\u4e49\u69fd\u51fd\u6570\u3002<\/p>\n<ul>\n<li>\n<p>onStateChanged()\u5728\u64ad\u653e\u5668\u64ad\u653e\u72b6\u6001\u53d8\u5316\u65f6\u53d1\u5c04&#xff0c;\u4ee5\u66f4\u65b0\u754c\u9762\u4e0a\u7684\u201c\u64ad\u653e\u201d\u201c\u6682\u505c\u201d\u201c\u505c\u6b62\u201d\u6309\u94ae\u7684\u4f7f\u80fd\u72b6\u6001\u3002<\/p>\n<\/li>\n<li>\n<p>onPlaylistChanged()\u5728\u64ad\u653e\u5217\u8868\u7684\u5f53\u524d\u6587\u4ef6\u53d8\u5316\u65f6\u53d1\u5c04&#xff0c;\u7528\u4ee5\u66f4\u65b0\u754c\u9762\u4e0a\u663e\u793a\u5f53\u524d\u5a92\u4f53\u6587\u4ef6\u540d\u3002<\/p>\n<\/li>\n<li>\n<p>onDurationChanged()\u5728\u6587\u4ef6\u65f6\u957f\u53d8\u5316\u65f6\u53d1\u5c04&#xff0c;\u7528\u4e8e\u66f4\u65b0\u754c\u9762\u4e0a\u6587\u4ef6\u65f6\u95f4\u957f\u5ea6\u7684\u663e\u793a\u3002<\/p>\n<\/li>\n<li>\n<p>onPositionChanged()\u5728\u5f53\u524d\u6587\u4ef6\u64ad\u653e\u4f4d\u7f6e\u53d8\u5316\u65f6\u53d1\u5c04&#xff0c;\u7528\u4e8e\u66f4\u65b0\u754c\u9762\u4e0a\u7684\u64ad\u653e\u8fdb\u5ea6\u663e\u793a\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u4e0b\u9762\u662fMainWindow\u6784\u9020\u51fd\u6570\u7684\u4ee3\u7801&#xff0c;\u4e3b\u8981\u529f\u80fd\u662f\u521b\u5efaplayer\u548cplaylist&#xff0c;\u7136\u540e\u8fdb\u884c\u4fe1\u53f7\u4e0e\u81ea\u5b9a\u4e49\u69fd\u51fd\u6570\u7684\u5173\u8054\u3002<\/p>\n<p>MainWindow::MainWindow(QWidget *parent) :   QMainWindow(parent),<br \/>\n   ui(new Ui::MainWindow)<br \/>\n{<br \/>\n   ui-&gt;setupUi(this);<br \/>\n   player &#061; new QMediaPlayer(this);\/\/\u64ad\u653e\u5668<br \/>\n   playlist &#061; new QMediaPlaylist(this);\/\/\u64ad\u653e\u5217\u8868<br \/>\n   playlist-&gt;setPlaybackMode(QMediaPlaylist::Loop); \/\/\u5faa\u73af\u6a21\u5f0f<br \/>\n   player-&gt;setPlaylist(playlist);<\/p>\n<p>   connect(player,SIGNAL(stateChanged(QMediaPlayer::State)),<br \/>\n         this, SLOT(onStateChanged(QMediaPlayer::State)));<br \/>\n   connect(player,SIGNAL(positionChanged(qint64)),<br \/>\n         this, SLOT(onPositionChanged(qint64)));<br \/>\n   connect(player,SIGNAL(durationChanged(qint64)),<br \/>\n         this, SLOT(onDurationChanged(qint64)));<br \/>\n   connect(playlist,SIGNAL(currentIndexChanged(int)),<br \/>\n         this, SLOT(onPlaylistChanged(int)));<br \/>\n}<\/p>\n<p>\u4e0b\u9762\u662f4\u4e2a\u81ea\u5b9a\u4e49\u69fd\u51fd\u6570\u7684\u4ee3\u7801&#xff1a;<\/p>\n<p>void MainWindow::onStateChanged(QMediaPlayer::State state)<br \/>\n{\/\/\u64ad\u653e\u5668\u72b6\u6001\u53d8\u5316&#xff0c;\u66f4\u65b0\u6309\u94ae\u72b6\u6001<br \/>\n   ui-&gt;btnPlay-&gt;setEnabled(!(state&#061;&#061;QMediaPlayer::PlayingState));<br \/>\n   ui-&gt;btnPause-&gt;setEnabled(state&#061;&#061;QMediaPlayer::PlayingState);<br \/>\n   ui-&gt;btnStop-&gt;setEnabled(state&#061;&#061;QMediaPlayer::PlayingState);<br \/>\n}<br \/>\nvoid MainWindow::onPlaylistChanged(int position)<br \/>\n{\/\/\u64ad\u653e\u5217\u8868\u53d8\u5316,\u66f4\u65b0\u5f53\u524d\u64ad\u653e\u6587\u4ef6\u540d\u663e\u793a<br \/>\n   ui-&gt;listWidget-&gt;setCurrentRow(position);<br \/>\n   QListWidgetItem  *item&#061;ui-&gt;listWidget-&gt;currentItem();<br \/>\n   if (item)<br \/>\n      ui-&gt;LabCurMedia-&gt;setText(item-&gt;text());<br \/>\n}<br \/>\nvoid MainWindow::onDurationChanged(qint64 duration)<br \/>\n{\/\/\u6587\u4ef6\u65f6\u957f\u53d8\u5316&#xff0c;\u66f4\u65b0\u8fdb\u5ea6\u663e\u793a<br \/>\n   ui-&gt;sliderPosition-&gt;setMaximum(duration);<br \/>\n    int   secs&#061;duration\/1000;\/\/\u79d2<br \/>\n    int   mins&#061;secs\/60; \/\/\u5206\u949f<br \/>\n    secs&#061;secs % 60;\/\/\u4f59\u6570\u79d2<br \/>\n    durationTime&#061;QString::asprintf(&#034;%d:%d&#034;,mins,secs);<br \/>\n    ui-&gt;LabRatio-&gt;setText(positionTime&#043;&#034;\/&#034;&#043;durationTime);<br \/>\n}<br \/>\nvoid MainWindow::onPositionChanged(qint64 position)<br \/>\n{\/\/\u5f53\u524d\u6587\u4ef6\u64ad\u653e\u4f4d\u7f6e\u53d8\u5316&#xff0c;\u66f4\u65b0\u8fdb\u5ea6\u663e\u793a<br \/>\n   if (ui-&gt;sliderPosition-&gt;isSliderDown())\/\/\u6b63\u5904\u4e8e\u624b\u52a8\u8c03\u6574\u72b6\u6001&#xff0c;\u4e0d\u5904\u7406<br \/>\n      return;<br \/>\n   ui-&gt;sliderPosition-&gt;setSliderPosition(position);<br \/>\n   int   secs&#061;position\/1000;\/\/\u79d2<br \/>\n   int   mins&#061;secs\/60; \/\/\u5206\u949f<br \/>\n   secs&#061;secs % 60;\/\/\u4f59\u6570\u79d2<br \/>\n   positionTime&#061;QString::asprintf(&#034;%d:%d&#034;,mins,secs);<br \/>\n   ui-&gt;LabRatio-&gt;setText(positionTime&#043;&#034;\/&#034;&#043;durationTime);<br \/>\n}<\/p>\n<h5>3&#xff0e;\u64ad\u653e\u5217\u8868\u63a7\u5236<\/h5>\n<p>\u7a97\u53e3\u4e2d\u95f4\u4ee5\u4e00\u4e2aQListWidget\u7ec4\u4ef6\u663e\u793a\u64ad\u653e\u7684\u6587\u4ef6\u5217\u8868&#xff0c;\u754c\u9762\u4e0a\u663e\u793a\u7684\u6587\u4ef6\u5217\u8868\u4e0eplaylist\u5b58\u50a8\u7684\u6587\u4ef6\u5217\u8868\u4fdd\u6301\u540c\u6b65\u3002<\/p>\n<p>\u7a97\u53e3\u4e0a\u65b9\u7684\u201c\u6dfb\u52a0\u201d\u201c\u79fb\u9664\u201d\u201c\u6e05\u7a7a\u201d3\u4e2a\u6309\u94ae\u7684\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_btnAdd_clicked()<br \/>\n{\/\/\u6dfb\u52a0\u6587\u4ef6<br \/>\n    QString curPath&#061;QDir::homePath();\/\/\u83b7\u53d6\u7528\u6237\u76ee\u5f55<br \/>\n    QString dlgTitle&#061;&#034;\u9009\u62e9\u97f3\u9891\u6587\u4ef6&#034;;<br \/>\n    QString filter&#061;&#034;\u97f3\u9891\u6587\u4ef6(*.mp3 *.wav *.wma);;mp3\u6587\u4ef6(*.mp3);;wav\u6587\u4ef6(*.wav);;wma\u6587\u4ef6(*.wma);;\u6240\u6709\u6587\u4ef6(*.*)&#034;;<br \/>\n    QStringList fileList&#061;QFileDialog::getOpenFileNames(this, dlgTitle, curPath, filter);<br \/>\n    if (fileList.count()&lt;1)<br \/>\n       return;<br \/>\n    for (int i&#061;0; i&lt;fileList.count();i&#043;&#043;)<br \/>\n    {<br \/>\n      QString aFile&#061;fileList.at(i);<br \/>\n      playlist-&gt;addMedia(QUrl::fromLocalFile(aFile));\/\/\u6dfb\u52a0\u6587\u4ef6<br \/>\n      QFileInfo   fileInfo(aFile);<br \/>\n      ui-&gt;listWidget-&gt;addItem(fileInfo.fileName());\/\/\u6dfb\u52a0\u5230\u754c\u9762\u6587\u4ef6\u5217\u8868<br \/>\n    }<br \/>\n    if (player-&gt;state()!&#061;QMediaPlayer::PlayingState)<br \/>\n       playlist-&gt;setCurrentIndex(0);<br \/>\n    player-&gt;play();<br \/>\n}<br \/>\nvoid MainWindow::on_btnRemove_clicked()<br \/>\n{\/\/\u79fb\u9664\u4e00\u4e2a\u6587\u4ef6<br \/>\n   int pos&#061;ui-&gt;listWidget-&gt;currentRow();<br \/>\n   QListWidgetItem *item&#061;ui-&gt;listWidget-&gt;takeItem(pos);<br \/>\n   delete item;\/\/\u4ecelistWidget\u91cc\u5220\u9664<br \/>\n   playlist-&gt;removeMedia(pos); \/\/\u4ece\u64ad\u653e\u5217\u8868\u91cc\u5220\u9664<br \/>\n}<br \/>\nvoid MainWindow::on_btnClear_clicked()<br \/>\n{\/\/\u6e05\u7a7a\u5217\u8868<br \/>\n   playlist-&gt;clear();<br \/>\n   ui-&gt;listWidget-&gt;clear();<br \/>\n   player-&gt;stop();<br \/>\n}<\/p>\n<p>\u7528\u5230\u7684QMediaPlaylist\u7684\u4e3b\u8981\u51fd\u6570\u6709&#xff1a;<\/p>\n<ul>\n<li>\n<p>addMedia()\u51fd\u6570\u6dfb\u52a0\u4e00\u4e2a\u6587\u4ef6&#xff1b;<\/p>\n<\/li>\n<li>\n<p>removeMedia()\u79fb\u9664\u4e00\u4e2a\u6587\u4ef6&#xff1b;<\/p>\n<\/li>\n<li>\n<p>setCurrentIndex()\u8bbe\u7f6e\u5f53\u524d\u64ad\u653e\u6587\u4ef6\u5e8f\u53f7&#xff1b;<\/p>\n<\/li>\n<li>\n<p>clear()\u6e05\u7a7a\u64ad\u653e\u5217\u8868\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5728\u64ad\u653e\u5217\u8868\u4e2d\u524d\u79fb\u548c\u540e\u79fb\u4f7f\u7528previous()\u548cnext()\u51fd\u6570&#xff0c;\u79fb\u52a8\u65f6\u64ad\u653e\u5217\u8868\u4f1a\u53d1\u5c04currentIndex Changed()\u4fe1\u53f7&#xff0c;\u4ece\u800c\u81ea\u52a8\u66f4\u65b0\u754c\u9762\u4e0alistWidget\u91cc\u7684\u5f53\u524d\u6761\u76ee\u3002<\/p>\n<p>\u5728\u754c\u9762\u4e0a\u7684listWidget\u91cc\u53cc\u51fb\u4e00\u4e2a\u6761\u76ee\u65f6&#xff0c;\u5207\u6362\u5230\u64ad\u653e\u8fd9\u4e2a\u6587\u4ef6&#xff0c;\u5176\u5b9e\u73b0\u4ee3\u7801\u4e3a&#xff1a;<\/p>\n<p>void MainWindow::on_listWidget_doubleClicked(const QModelIndex &amp;index)<br \/>\n{\/\/\u53cc\u51fb\u65f6\u5207\u6362\u64ad\u653e\u6587\u4ef6<br \/>\n   int rowNo&#061;index.row();<br \/>\n   playlist-&gt;setCurrentIndex(rowNo);<br \/>\n   player-&gt;play();<br \/>\n}<\/p>\n<h5>4&#xff0e;\u64ad\u653e\u63a7\u5236<\/h5>\n<p>\u64ad\u653e\u3001\u6682\u505c\u6216\u505c\u6b62\u64ad\u653e\u5668&#xff0c;\u53ea\u9700\u8c03\u7528QMediaPlayer\u76f8\u5e94\u51fd\u6570\u5373\u53ef&#xff0c;\u754c\u9762\u4e0a3\u4e2a\u6309\u94ae\u7684\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_btnPlay_clicked()<br \/>\n{\/\/\u64ad\u653e<br \/>\n   if (playlist-&gt;currentIndex()&lt;0)<br \/>\n      playlist-&gt;setCurrentIndex(0);<br \/>\n   player-&gt;play();<br \/>\n}<br \/>\nvoid MainWindow::on_btnPause_clicked()<br \/>\n{\/\/\u6682\u505c\u64ad\u653e<br \/>\n   player-&gt;pause();<br \/>\n}<br \/>\nvoid MainWindow::on_btnStop_clicked()<br \/>\n{\/\/\u505c\u6b62\u64ad\u653e<br \/>\n   player-&gt;stop();<br \/>\n}<\/p>\n<p>\u64ad\u653e\u72b6\u6001\u53d8\u5316\u65f6\u4f1a\u53d1\u5c04stateChanged()\u4fe1\u53f7&#xff0c;\u5728\u5173\u8054\u7684\u81ea\u5b9a\u4e49\u69fd\u51fd\u6570onStateChanged()\u91cc\u66f4\u65b03\u4e2a\u6309\u94ae\u7684\u4f7f\u80fd\u72b6\u6001\u3002<\/p>\n<p>\u97f3\u91cf\u63a7\u5236\u7531\u4e00\u4e2a\u201c\u9759\u97f3\u201d\u6309\u94ae\u548c\u97f3\u91cf\u6ed1\u52a8\u6761\u63a7\u5236&#xff0c;\u76f8\u5173\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_btnSound_clicked()<br \/>\n{\/\/\u9759\u97f3\u63a7\u5236<br \/>\n   bool mute&#061;player-&gt;isMuted();<br \/>\n   player-&gt;setMuted(!mute);<br \/>\n   if (mute)<br \/>\n      ui-&gt;btnSound-&gt;setIcon(QIcon(&#034;:\/images\/images\/volumn.bmp&#034;));<br \/>\n   else<br \/>\n      ui-&gt;btnSound-&gt;setIcon(QIcon(&#034;:\/images\/images\/mute.bmp&#034;));<br \/>\n}<br \/>\nvoid MainWindow::on_sliderVolumn_valueChanged(int value)<br \/>\n{\/\/\u8c03\u6574\u97f3\u91cf<br \/>\n   player-&gt;setVolume(value);<br \/>\n}<\/p>\n<p>\u6587\u4ef6\u64ad\u653e\u8fdb\u5ea6\u6761\u5728onDurationChanged()\u548conPositionChanged()\u4e24\u4e2a\u81ea\u5b9a\u4e49\u69fd\u51fd\u6570\u91cc\u4f1a\u66f4\u65b0&#xff0c;\u663e\u793a\u5f53\u524d\u6587\u4ef6\u64ad\u653e\u8fdb\u5ea6\u3002\u5f53\u62d6\u52a8\u6ed1\u52a8\u6761\u7684\u6ed1\u5757\u53ef\u4ee5\u8bbe\u7f6e\u6587\u4ef6\u64ad\u653e\u4f4d\u7f6e&#xff0c;\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_sliderPosition_valueChanged(int value)<br \/>\n{\/\/\u6587\u4ef6\u8fdb\u5ea6\u8c03\u63a7<br \/>\n   player-&gt;setPosition(value);<br \/>\n}<\/p>\n<h4>15.2.2\u3000\u4f7f\u7528QSoundEffect\u548cQSound\u64ad\u653e\u97f3\u6548\u6587\u4ef6<\/h4>\n<p>QSoundEffect\u7528\u4e8e\u64ad\u653e\u4f4e\u5ef6\u8fdf\u7684\u97f3\u6548\u6587\u4ef6&#xff0c;\u5982\u65e0\u538b\u7f29\u7684WAV\u6587\u4ef6&#xff0c;\u7528\u4e8e\u5b9e\u73b0\u4e00\u4e9b\u97f3\u6548\u6548\u679c&#xff0c;\u5982\u6309\u952e\u97f3\u3001\u63d0\u793a\u97f3\u7b49\u3002\u4f7f\u7528QSoundEffect\u64ad\u653e\u97f3\u6548\u6587\u4ef6\u7684\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>QSoundEffect effect;<br \/>\neffect.setSource(QUrl::fromLocalFile(&#034;engine.wav&#034;));<br \/>\neffect.setLoopCount(3);<br \/>\neffect.setVolume(1);<br \/>\neffect.play();<\/p>\n<p>QSoundEffect\u4e0d\u4ec5\u53ef\u4ee5\u64ad\u653e\u672c\u5730\u6587\u4ef6&#xff0c;\u8fd8\u53ef\u4ee5\u64ad\u653e\u7f51\u7edc\u6587\u4ef6\u3002<\/p>\n<p>\u8fd8\u6709\u4e00\u4e2a\u7c7bQSound\u53ea\u80fd\u64ad\u653e\u672c\u5730WAV\u6587\u4ef6&#xff0c;\u800c\u4e14\u662f\u5f02\u6b65\u65b9\u5f0f\u64ad\u653e\u3002\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528QSound\u7684\u9759\u6001\u51fd\u6570\u64ad\u653eWAV\u6587\u4ef6&#xff0c;\u5982&#xff1a;<\/p>\n<p>QSound::play(&#034;mysounds\/bells.wav&#034;);<\/p>\n<h3>15.3\u3000\u97f3\u9891\u8f93\u5165<\/h3>\n<p>\u97f3\u9891\u8f93\u5165\u53ef\u4ee5\u4f7f\u7528QAudioRecorder\u6216QAudioInput\u4e24\u4e2a\u7c7b\u5b9e\u73b0\u3002QAudioRecorder\u662f\u9ad8\u5c42\u6b21\u7684\u5b9e\u73b0&#xff0c;\u8f93\u5165\u7684\u97f3\u9891\u6570\u636e\u76f4\u63a5\u4fdd\u5b58\u4e3a\u6587\u4ef6&#xff0c;\u4e5f\u53ef\u4ee5\u901a\u8fc7QAudioProbe\u8bbf\u95ee\u539f\u59cb\u7684\u97f3\u9891\u6570\u636e\u3002QAudioInput\u662f\u4f4e\u5c42\u6b21\u7684\u5b9e\u73b0&#xff0c;\u76f4\u63a5\u63a7\u5236\u97f3\u9891\u8f93\u5165\u8bbe\u5907\u7684\u53c2\u6570&#xff0c;\u5e76\u5c06\u97f3\u9891\u5f55\u5236\u6570\u636e\u5199\u5165\u4e00\u4e2a\u6d41\u8bbe\u5907\u3002<\/p>\n<h4>15.3.1\u3000\u4f7f\u7528QAudioRecorder\u5f55\u5236\u97f3\u9891<\/h4>\n<h5>1&#xff0e;\u4f7f\u7528QAudioRecorder\u5f55\u5236\u97f3\u9891<\/h5>\n<p>QAudioRecorder\u662f\u7528\u4e8e\u5f55\u5236\u97f3\u9891\u7684\u7c7b&#xff0c;\u5b83\u4eceQMediaRecorder\u7c7b\u7ee7\u627f\u800c\u6765&#xff0c;\u53ea\u9700\u8981\u8f83\u5c11\u7684\u4ee3\u7801&#xff0c;\u5c31\u53ef\u4ee5\u5b9e\u73b0\u97f3\u9891\u5f55\u5236\u5e76\u5b58\u50a8\u5230\u6587\u4ef6\u3002\u539f\u4e66\u7684\u56fe15-2\u662f\u4f7f\u7528QAudioRecorder\u5f55\u5236\u97f3\u9891\u6587\u4ef6\u7684\u5b9e\u4f8b\u7a0b\u5e8fsamp15_3\u8fd0\u884c\u65f6\u754c\u9762\u3002<\/p>\n<p>QAudioRecorder\u9700\u8981\u4f7f\u7528\u4e00\u4e2aQAudioEncoderSettings\u7c7b\u578b\u7684\u53d8\u91cf\u8fdb\u884c\u8f93\u5165\u97f3\u9891\u8bbe\u7f6e&#xff0c;\u4e3b\u8981\u662f\u7f16\u7801\u683c\u5f0f\u3001\u91c7\u6837\u7387\u3001\u901a\u9053\u6570\u3001\u97f3\u9891\u8d28\u91cf\u7b49\u9ad8\u7ea7\u8bbe\u7f6e&#xff0c;\u56fe15-2\u7a97\u53e3\u5de6\u4fa7\u662f\u97f3\u9891\u8f93\u5165\u8bbe\u7f6e\u3002<\/p>\n<p>\u8bbe\u7f6e\u4e00\u4e2a\u8f93\u51fa\u4fdd\u5b58\u6587\u4ef6\u540e\u5c31\u53ef\u4ee5\u4f7f\u7528QAudioRecorder\u5f55\u5236\u6587\u4ef6&#xff0c;\u5f55\u5236\u7684\u6570\u636e\u4f1a\u81ea\u52a8\u4fdd\u5b58\u5230\u6587\u4ef6\u91cc\u3002\u97f3\u9891\u8f93\u5165\u8bbe\u5907\u4f1a\u6839\u636e\u97f3\u9891\u8bbe\u7f6e\u81ea\u52a8\u786e\u5b9a\u5e95\u5c42\u7684\u91c7\u6837\u53c2\u6570&#xff0c;\u4f7f\u7528QAudioProbe\u7c7b\u53ef\u4ee5\u83b7\u53d6\u97f3\u9891\u8f93\u5165\u7f13\u51b2\u533a\u7684\u53c2\u6570\u548c\u539f\u59cb\u6570\u636e\u3002\u56fe15-2\u7a97\u53e3\u53f3\u4fa7\u663e\u793a\u4e86\u97f3\u9891\u8f93\u5165\u7f13\u51b2\u533a\u7684\u6570\u636e\u53c2\u6570&#xff0c;\u5305\u62ec\u7f13\u51b2\u533a\u5b57\u8282\u6570\u3001\u5e27\u6570\u3001\u91c7\u6837\u6570\u3001\u91c7\u6837\u5b57\u957f\u3001\u91c7\u6837\u7387\u7b49&#xff0c;\u901a\u8fc7\u8fd9\u4e9b\u53c2\u6570\u5c31\u53ef\u4ee5\u4ece\u7f13\u51b2\u533a\u8bfb\u53d6\u51fa\u539f\u59cb\u7684\u97f3\u9891\u6570\u636e\u3002<\/p>\n<h5>2&#xff0e;QAudioRecorder\u5f55\u97f3\u529f\u80fd\u7684\u5b9e\u73b0<\/h5>\n<p>samp15_3\u7684\u4e3b\u7a97\u53e3\u4eceQMainWindow\u7ee7\u627f&#xff0c;\u754c\u9762\u91c7\u7528UI\u8bbe\u8ba1\u5668\u8bbe\u8ba1&#xff0c;\u754c\u9762\u7ec4\u4ef6\u548c\u5e03\u5c40\u7684\u8bbe\u8ba1\u4e0d\u518d\u8be6\u8ff0\u3002\u4e3b\u7a97\u53e3\u7c7bMainWindow\u7684\u5b9a\u4e49\u5982\u4e0b&#xff08;\u7701\u7565\u4e86UI\u751f\u6210\u7684\u754c\u9762\u7ec4\u4ef6\u7684\u69fd\u51fd\u6570\u5b9a\u4e49&#xff09;&#xff1a;<\/p>\n<p>class MainWindow : public QMainWindow<br \/>\n{<br \/>\n   Q_OBJECT<br \/>\nprivate:<br \/>\n   QAudioRecorder *recorder;\/\/\u97f3\u9891\u5f55\u97f3<br \/>\n   QAudioProbe *probe; \/\/\u63a2\u6d4b\u5668<br \/>\npublic:<br \/>\n   explicit MainWindow(QWidget *parent &#061; 0);<br \/>\nprivate slots:<br \/>\n\/\/\u81ea\u5b9a\u4e49\u69fd\u51fd\u6570<br \/>\n   void onStateChanged(QMediaRecorder::State state);<br \/>\n   void onDurationChanged(qint64 duration);<br \/>\n   void processBuffer(const QAudioBuffer&amp; buffer);<br \/>\nprivate:<br \/>\n   Ui::MainWindow *ui;<br \/>\n};<\/p>\n<p>QAudioRecorder\u7c7b\u578b\u53d8\u91cfrecorder\u7528\u4e8e\u5f55\u97f3&#xff0c;QAudioProbe\u7c7b\u578b\u53d8\u91cfprobe\u7528\u4e8e\u63a2\u6d4b\u7f13\u51b2\u533a\u6570\u636e\u3002<\/p>\n<p>\u8fd8\u5b9a\u4e49\u4e863\u4e2a\u69fd\u51fd\u6570&#xff0c;\u7528\u4e8e\u4e0erecorder\u548cprobe\u7684\u4fe1\u53f7\u8fdb\u884c\u5173\u8054\u3002\u5728\u7a97\u53e3\u7684\u6784\u9020\u51fd\u6570\u91cc\u521b\u5efa\u53d8\u91cf\u548c\u8fdb\u884c\u4fe1\u53f7\u4e0e\u69fd\u7684\u5173\u8054\u3002\u4e0b\u9762\u662f\u7a97\u53e3\u6784\u9020\u51fd\u6570\u7684\u4ee3\u7801&#xff1a;<\/p>\n<p>MainWindow::MainWindow(QWidget *parent) :   QMainWindow(parent),<br \/>\n   ui(new Ui::MainWindow)<br \/>\n{  ui-&gt;setupUi(this);<br \/>\n   recorder &#061; new QAudioRecorder(this);<br \/>\n   connect(recorder,SIGNAL(stateChanged(QMediaRecorder::State)),<br \/>\n          this,SLOT(onStateChanged(QMediaRecorder::State)));<br \/>\n   connect(recorder, SIGNAL(durationChanged(qint64)), this,<br \/>\n          SLOT(onDurationChanged(qint64)));<\/p>\n<p>   probe &#061; new QAudioProbe;\/\/\u63a2\u6d4b\u5668<br \/>\n   connect(probe, SIGNAL(audioBufferProbed(QAudioBuffer)),<br \/>\n          this, SLOT(processBuffer(QAudioBuffer)));<br \/>\n   probe-&gt;setSource(recorder);<\/p>\n<p>   if (recorder-&gt;defaultAudioInput().isEmpty())<br \/>\n      return;  \/\/\u65e0\u97f3\u9891\u8f93\u5165\u8bbe\u5907<br \/>\n   foreach (const QString &amp;device, recorder-&gt;audioInputs())<br \/>\n      ui-&gt;comboDevices-&gt;addItem(device); \/\/\u97f3\u9891\u8f93\u5165\u8bbe\u5907\u5217\u8868<br \/>\n   foreach (const QString &amp;codecName, recorder-&gt;supportedAudioCodecs())<br \/>\n      ui-&gt;comboCodec-&gt;addItem(codecName); \/\/\u652f\u6301\u7684\u97f3\u9891\u7f16\u7801<br \/>\n   foreach (int sampleRate, recorder-&gt;supportedAudioSampleRates())<br \/>\n      ui-&gt;comboSampleRate-&gt;addItem(QString::number(sampleRate)); \/\/\u91c7\u6837\u7387<br \/>\n   \/\/channels<br \/>\n   ui-&gt;comboChannels-&gt;addItem(&#034;1&#034;);<br \/>\n   ui-&gt;comboChannels-&gt;addItem(&#034;2&#034;);<br \/>\n   ui-&gt;comboChannels-&gt;addItem(&#034;4&#034;);<br \/>\n   \/\/quality<br \/>\n   ui-&gt;sliderQuality-&gt;setRange(0, int(QMultimedia::VeryHighQuality));<br \/>\n   ui-&gt;sliderQuality-&gt;setValue(int(QMultimedia::NormalQuality));<br \/>\n   \/\/bitrates:<br \/>\n   ui-&gt;comboBitrate-&gt;addItem(&#034;32000&#034;);<br \/>\n   ui-&gt;comboBitrate-&gt;addItem(&#034;64000&#034;);<br \/>\n   ui-&gt;comboBitrate-&gt;addItem(&#034;96000&#034;);<br \/>\n   ui-&gt;comboBitrate-&gt;addItem(&#034;128000&#034;);<br \/>\n}<\/p>\n<p>\u69fd\u51fd\u6570onStateChanged()\u4e0erecorder\u7684stateChanged()\u4fe1\u53f7\u5173\u8054&#xff0c;\u5728recorder\u7684\u72b6\u6001\u53d8\u5316\u65f6\u63a7\u5236\u754c\u9762\u4e0a\u201c\u5f55\u97f3\u201d\u201c\u6682\u505c\u201d\u201c\u505c\u6b62\u201d\u7b49\u6309\u94ae\u7684\u4f7f\u80fd\u72b6\u6001\u3002<\/p>\n<p>\u69fd\u51fd\u6570onDurationChanged()\u4e0erecorder\u7684durationChanged()\u4fe1\u53f7\u5173\u8054&#xff0c;\u8be5\u4fe1\u53f7\u5728\u5f55\u5236\u6301\u7eed\u65f6\u95f4\u53d8\u5316\u65f6\u53d1\u5c04&#xff0c;\u4ee5\u66f4\u65b0\u754c\u9762\u4e0a\u7684\u65f6\u95f4\u663e\u793a\u3002\u4e0b\u9762\u662f\u8fd9\u4e24\u4e2a\u69fd\u51fd\u6570\u7684\u4ee3\u7801&#xff1a;<\/p>\n<p>void MainWindow::onStateChanged(QMediaRecorder::State state)<br \/>\n{ \/\/\u5f55\u97f3\u72b6\u6001\u53d8\u5316<br \/>\n   ui-&gt;actRecord-&gt;setEnabled(state!&#061;QMediaRecorder::RecordingState);<br \/>\n   ui-&gt;actPause-&gt;setEnabled(state&#061;&#061;QMediaRecorder::RecordingState);<br \/>\n   ui-&gt;actStop-&gt;setEnabled(state&#061;&#061;QMediaRecorder::RecordingState);<br \/>\n   ui-&gt;btnGetFile-&gt;setEnabled(state&#061;&#061;QMediaRecorder::StoppedState);<br \/>\n   ui-&gt;editOutputFile-&gt;setEnabled(state&#061;&#061;QMediaRecorder::StoppedState);<br \/>\n}<br \/>\nvoid MainWindow::onDurationChanged(qint64 duration)<br \/>\n{\/\/\u5f55\u97f3\u6301\u7eed\u65f6\u95f4\u53d8\u5316<br \/>\n   ui-&gt;LabPassTime-&gt;setText(QString(&#034;\u5df2\u5f55\u5236 %1 \u79d2&#034;).arg(duration \/ 1000));<br \/>\n}<\/p>\n<p>\u63a2\u6d4b\u5668probe\u901a\u8fc7setSource()\u6307\u5b9a\u63a2\u6d4b\u5bf9\u8c61&#xff0c;\u8fd9\u91ccprobe\u7684\u63a2\u6d4b\u5bf9\u8c61\u662frecorder\u3002<\/p>\n<p>probe-&gt;setSource(recorder);<\/p>\n<p>QAudioProbe\u4e5f\u53ef\u4ee5\u5728\u97f3\u9891\u64ad\u653e\u65f6\u8fdb\u884c\u7f13\u51b2\u533a\u63a2\u6d4b&#xff0c;\u4e5f\u5c31\u662f\u53ef\u4ee5\u6307\u5b9a\u4e00\u4e2aQMediaPlayer\u5bf9\u8c61\u4f5c\u4e3a\u63a2\u6d4b\u5bf9\u8c61\u3002<\/p>\n<p>\u69fd\u51fd\u6570processBuffer()\u4e0eprobe\u7684\u4fe1\u53f7audioBufferProbed()\u5173\u8054&#xff0c;\u8fd9\u4e2a\u4fe1\u53f7\u4f1a\u4f20\u9012\u4e00\u4e2aQAudioBuffer\u7c7b\u578b\u7684\u53d8\u91cf&#xff0c;\u8fd9\u4e2a\u53d8\u91cf\u91cc\u5b58\u50a8\u4e86\u7f13\u51b2\u533a\u7684\u4fe1\u606f\u548c\u97f3\u9891\u539f\u59cb\u6570\u636e\u3002<\/p>\n<p>\u6784\u9020\u51fd\u6570\u7684\u540e\u90e8\u5206\u5bf9\u754c\u9762\u4e0a\u5f55\u97f3\u8bbe\u7f6e\u7684\u7ec4\u4ef6\u7684\u5185\u5bb9\u8fdb\u884c\u521d\u59cb\u5316&#xff0c;\u7528\u5230QAudioRecorder\u7c7b\u7684\u5982\u4e0b\u4e00\u4e9b\u51fd\u6570&#xff1a;<\/p>\n<ul>\n<li>\n<p>defaultAudioInput()\u51fd\u6570\u83b7\u53d6\u7f3a\u7701\u7684\u97f3\u9891\u8f93\u5165\u8bbe\u5907\u540d\u79f0&#xff1b;<\/p>\n<\/li>\n<li>\n<p>audioInputs()\u51fd\u6570\u83b7\u53d6\u97f3\u9891\u8f93\u5165\u8bbe\u5907\u5217\u8868&#xff1b;<\/p>\n<\/li>\n<li>\n<p>supportedAudioCodecs()\u51fd\u6570\u83b7\u53d6\u652f\u6301\u7684\u97f3\u9891\u7f16\u7801\u5217\u8868&#xff1b;<\/p>\n<\/li>\n<li>\n<p>supportedAudioSampleRates()\u83b7\u53d6\u652f\u6301\u7684\u97f3\u9891\u91c7\u6837\u7387\u5217\u8868\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u9009\u62e9\u4e00\u4e2a\u5f55\u97f3\u8f93\u51fa\u6587\u4ef6\u540e&#xff0c;\u5c31\u53ef\u4ee5\u901a\u8fc7\u754c\u9762\u4e0a\u201c\u5f55\u97f3\u201d\u201c\u6682\u505c\u201d\u201c\u505c\u6b62\u201d\u4e09\u4e2a\u6309\u94ae\u8fdb\u884c\u5f55\u97f3\u63a7\u5236&#xff0c;\u4e09\u4e2a\u6309\u94ae\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_actRecord_triggered()<br \/>\n{ \/\/\u5f00\u59cb\u5f55\u97f3<br \/>\n   if (recorder-&gt;state() &#061;&#061; QMediaRecorder::StoppedState) \/\/\u5df2\u505c\u6b62&#xff0c;\u91cd\u65b0\u8bbe\u7f6e<br \/>\n   {<br \/>\n     QString selectedFile&#061;ui-&gt;editOutputFile-&gt;text().trimmed();<br \/>\n     if (selectedFile.isEmpty())<br \/>\n     {<br \/>\n       QMessageBox::critical(this,&#034;\u9519\u8bef&#034;,&#034;\u8bf7\u5148\u8bbe\u7f6e\u5f55\u97f3\u8f93\u51fa\u6587\u4ef6&#034;);<br \/>\n       return;<br \/>\n     }<br \/>\n     if (QFile::exists(selectedFile))<br \/>\n      if (!QFile::remove(selectedFile))<br \/>\n      {<br \/>\n       QMessageBox::critical(this,&#034;\u9519\u8bef&#034;,&#034;\u6240\u8bbe\u7f6e\u5f55\u97f3\u8f93\u51fa\u6587\u4ef6\u65e0\u6cd5\u5220\u9664&#034;);<br \/>\n       return;<br \/>\n      }<br \/>\n     recorder-&gt;setOutputLocation(QUrl::fromLocalFile(selectedFile));<br \/>\n     recorder-&gt;setAudioInput(ui-&gt;comboDevices-&gt;currentText()); \/\/\u8f93\u5165\u8bbe\u5907<br \/>\n     QAudioEncoderSettings settings; \/\/\u97f3\u9891\u7f16\u7801\u8bbe\u7f6e<br \/>\n     settings.setCodec(ui-&gt;comboCodec-&gt;currentText());\/\/\u7f16\u7801<br \/>\n     settings.setSampleRate(ui-&gt;comboSampleRate-&gt;currentText().toInt());<br \/>\n     settings.setBitRate(ui-&gt;comboBitrate-&gt;currentText().toInt());\/\/\u6bd4\u7279\u7387<br \/>\n     settings.setChannelCount(ui-&gt;comboChannels-&gt;currentText().toInt());<br \/>\n     settings.setQuality(QMultimedia::EncodingQuality(<br \/>\n              ui-&gt;sliderQuality-&gt;value()));<br \/>\n     if (ui-&gt;radioQuality-&gt;isChecked())\/\/\u7f16\u7801\u6a21\u5f0f\u4e3a\u56fa\u5b9a\u54c1\u8d28<br \/>\n       settings.setEncodingMode(QMultimedia::ConstantQualityEncoding);<br \/>\n     else<br \/>\n       settings.setEncodingMode(QMultimedia::ConstantBitRateEncoding);<br \/>\n     recorder-&gt;setAudioSettings(settings); \/\/\u97f3\u9891\u8bbe\u7f6e<br \/>\n   }<br \/>\n   recorder-&gt;record();<br \/>\n}<br \/>\nvoid MainWindow::on_actPause_triggered()<br \/>\n{ \/\/\u6682\u505c<br \/>\n   recorder-&gt;pause();<br \/>\n}<br \/>\nvoid MainWindow::on_actStop_triggered()<br \/>\n{\/\/\u505c\u6b62<br \/>\n   recorder-&gt;stop();<br \/>\n}<\/p>\n<p>\u5f00\u59cb\u3001\u6682\u505c\u548c\u505c\u6b62\u5f55\u97f3\u53ea\u9700\u8c03\u7528QAudioRecorder\u7684record()\u3001pause()\u548cstop()\u51fd\u6570&#xff0c;\u8fd9\u4f1a\u5bfc\u81f4QAudioRecorder\u7684state()\u53d1\u751f\u53d8\u5316&#xff0c;\u5e76\u53d1\u5c04stateChanged()\u4fe1\u53f7&#xff0c;\u5728\u5173\u8054\u7684\u69fd\u51fd\u6570onStateChanged()\u91cc\u66f4\u65b0\u754c\u9762\u6309\u94ae\u7684\u4f7f\u80fd\u72b6\u6001\u3002<\/p>\n<p>\u5728\u201c\u5f55\u97f3\u201d\u6309\u94ae\u7684\u4ee3\u7801\u91cc&#xff0c;\u5982\u679c\u662f\u4ece\u505c\u6b62\u72b6\u6001\u5355\u51fb\u201c\u5f55\u97f3\u201d&#xff0c;\u5c06\u4f1a\u6839\u636e\u754c\u9762\u7684\u8f93\u5165\u7528setOutput Location()\u8bbe\u7f6e\u4fdd\u5b58\u6587\u4ef6&#xff1b;\u5e76\u7528setAudioInput()\u8bbe\u7f6e\u97f3\u9891\u8f93\u5165\u8bbe\u5907&#xff1b;\u7136\u540e\u7528\u4e00\u4e2aQaudioEncoder Settings\u7c7b\u578b\u53d8\u91cfsettings\u83b7\u53d6\u5f55\u97f3\u8bbe\u7f6e&#xff0c;\u8bbe\u7f6e\u7684\u5185\u5bb9\u5305\u62ec&#xff1a;<\/p>\n<ul>\n<li>\n<p>setCodec()\u8bbe\u7f6e\u97f3\u9891\u7f16\u7801&#xff0c;\u5982\u201caudio\/pcm\u201d\u662f\u672a\u7ecf\u7f16\u7801\u7684\u97f3\u9891\u683c\u5f0f&#xff1b;<\/p>\n<\/li>\n<li>\n<p>setSampleRate()\u8bbe\u7f6e\u91c7\u6837\u7387&#xff0c;\u59828000Hz\u662f\u6700\u4f4e\u7684\u91c7\u6837\u7387&#xff0c;44100Hz\u662f\u4e00\u822cCD\u3001MP3\u7684\u91c7\u6837\u7387&#xff0c;96000Hz\u662f\u9ad8\u6e05\u6670\u97f3\u8f68\u4f7f\u7528\u7684\u91c7\u6837\u7387&#xff1b;<\/p>\n<\/li>\n<li>\n<p>setChannelCount()\u8bbe\u7f6e\u901a\u9053\u6570&#xff0c;\u5e38\u89c1\u7684\u6709\u5355\u58f0\u9053\u3001\u7acb\u4f53\u58f0&#xff08;\u53cc\u58f0\u9053&#xff09;\u548c\u56db\u58f0\u73af\u7ed5&#xff08;\u56db\u58f0\u9053&#xff09;&#xff1b;<\/p>\n<\/li>\n<li>\n<p>setBitRate()\u8bbe\u7f6e\u6bd4\u7279\u7387&#xff0c;\u82e5\u7528QAudioEncoderSettings::setEncodingMode()\u8bbe\u7f6e&#xff0c;\u7f16\u7801\u6a21\u5f0f\u4e3aQMultimedia::ConstantBitRateEncoding&#xff0c;\u5219\u97f3\u9891\u8f93\u5165\u8bbe\u5907\u91c7\u7528\u56fa\u5b9a\u7684\u6bd4\u7279\u7387\u91c7\u6837&#xff0c;\u6bd4\u7279\u7387\u8d8a\u9ad8&#xff0c;\u97f3\u8d28\u8d8a\u597d&#xff0c;\u4e00\u822c\u8f83\u9ad8\u97f3\u8d28\u5982128 kbps&#xff1b;<\/p>\n<\/li>\n<li>\n<p>setQuality()\u8bbe\u7f6e\u5f55\u97f3\u8d28\u91cf&#xff0c;\u4f20\u9012\u7684\u53c2\u6570\u662f\u8868\u793a\u5f55\u97f3\u8d28\u91cf\u7684\u679a\u4e3e\u7c7b\u578bQMultimedia::Encoding Quality&#xff0c;\u6709\u201cVeryLowQuality\u201d\u5230\u201cVeryHighQuality\u201d\u4e94\u4e2a\u7b49\u7ea7\u3002\u82e5\u7f16\u7801\u6a21\u5f0f\u8bbe\u7f6e\u4e3a\u56fa\u5b9a\u8d28\u91cf&#xff0c;\u5219\u97f3\u9891\u8f93\u5165\u8bbe\u5907\u4f1a\u6839\u636e\u8d28\u91cf\u8981\u6c42\u81ea\u52a8\u8bbe\u7f6e\u5e95\u5c42\u7684\u91c7\u6837\u7387\u3001\u5b57\u957f\u7b49\u53c2\u6570\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5728\u914d\u7f6e\u597dsettings\u7684\u5185\u5bb9\u540e&#xff0c;\u4e3a\u5f55\u97f3\u5668\u8bbe\u7f6e\u97f3\u9891\u53c2\u6570&#xff0c;\u5373&#xff1a;<\/p>\n<p>recorder-&gt;setAudioSettings(settings);<\/p>\n<h5>3&#xff0e;QAudioProbe \u83b7\u53d6\u97f3\u9891\u8f93\u5165\u7f13\u51b2\u533a\u6570\u636e\u53c2\u6570<\/h5>\n<p>\u5355\u51fb\u201c\u5f55\u97f3\u201d\u6309\u94ae\u540e&#xff0c;\u5c31\u53ef\u4ee5\u6839\u636e\u8bbe\u7f6e\u8fdb\u884c\u5f55\u97f3&#xff0c;\u5f55\u97f3\u7684\u6570\u636e\u4f1a\u81ea\u52a8\u4fdd\u5b58\u5230\u6307\u5b9a\u7684\u5b58\u50a8\u6587\u4ef6\u91cc\u3002<\/p>\n<p>\u7531\u4e8e\u4f7f\u7528\u4e86\u4e00\u4e2aQAudioProbe\u7c7b\u578b\u53d8\u91cfprobe\u8fdb\u884c\u5f55\u97f3\u6570\u636e\u7684\u63a2\u6d4b&#xff0c;\u5728\u5f55\u97f3\u8fc7\u7a0b\u4e2d&#xff0c;probe\u4f1a\u5728\u5f55\u97f3\u7684\u7f13\u51b2\u533a\u66f4\u65b0\u6570\u636e\u540e\u53d1\u5c04audioBufferProbed()\u4fe1\u53f7\u3002\u4e0eaudioBufferProbed()\u4fe1\u53f7\u5173\u8054\u7684\u81ea\u5b9a\u4e49\u69fd\u51fd\u6570processBuffer()\u5bf9\u7f13\u51b2\u533a\u7684\u6570\u636e\u4fe1\u606f\u8fdb\u884c\u67e5\u8be2\u548c\u663e\u793a&#xff0c;\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::processBuffer(const QAudioBuffer &amp;buffer)<br \/>\n{ \/\/\u5904\u7406\u63a2\u6d4b\u5230\u7684\u7f13\u51b2\u533a<br \/>\n   ui-&gt;spin_byteCount-&gt;setValue(buffer.byteCount());\/\/\u7f13\u51b2\u533a\u5b57\u8282\u6570<br \/>\n   ui-&gt;spin_duration-&gt;setValue(buffer.duration()\/1000);\/\/\u7f13\u51b2\u533a\u65f6\u957f<br \/>\n   ui-&gt;spin_frameCount-&gt;setValue(buffer.frameCount());\/\/\u7f13\u51b2\u533a\u5e27\u6570<br \/>\n   ui-&gt;spin_sampleCount-&gt;setValue(buffer.sampleCount());\/\/\u7f13\u51b2\u533a\u91c7\u6837\u6570<br \/>\n   QAudioFormat audioFormat&#061;buffer.format();\/\/\u7f13\u51b2\u533a\u683c\u5f0f<br \/>\n   ui-&gt;spin_channelCount-&gt;setValue(audioFormat.channelCount()); \/\/\u901a\u9053\u6570<br \/>\n   ui-&gt;spin_sampleSize-&gt;setValue(audioFormat.sampleSize());\/\/\u91c7\u6837\u5927\u5c0f<br \/>\n   ui-&gt;spin_sampleRate-&gt;setValue(audioFormat.sampleRate());\/\/\u91c7\u6837\u7387<br \/>\n   ui-&gt;spin_bytesPerFrame-&gt;setValue(audioFormat.bytesPerFrame());<br \/>\n   if (audioFormat.byteOrder()&#061;&#061;QAudioFormat::LittleEndian)<br \/>\n      ui-&gt;edit_byteOrder-&gt;setText(&#034;LittleEndian&#034;);\/\/\u5b57\u8282\u5e8f<br \/>\n   else<br \/>\n      ui-&gt;edit_byteOrder-&gt;setText(&#034;BigEndian&#034;);<br \/>\n   ui-&gt;edit_codec-&gt;setText(audioFormat.codec());\/\/\u7f16\u7801\u683c\u5f0f<\/p>\n<p>   if (audioFormat.sampleType()&#061;&#061;QAudioFormat::SignedInt)\/\/\u91c7\u6837\u70b9\u7c7b\u578b<br \/>\n      ui-&gt;edit_sampleType-&gt;setText(&#034;SignedInt&#034;);<br \/>\n   else if(audioFormat.sampleType()&#061;&#061;QAudioFormat::UnSignedInt)<br \/>\n      ui-&gt;edit_sampleType-&gt;setText(&#034;UnSignedInt&#034;);<br \/>\n   else if(audioFormat.sampleType()&#061;&#061;QAudioFormat::Float)<br \/>\n      ui-&gt;edit_sampleType-&gt;setText(&#034;Float&#034;);<br \/>\n   else<br \/>\n      ui-&gt;edit_sampleType-&gt;setText(&#034;Unknown&#034;);<br \/>\n}<\/p>\n<p>\u4fe1\u53f7audioBufferProbed()\u4f20\u9012\u4e00\u4e2aQAudioBuffer\u7c7b\u578b\u7684\u53c2\u6570buffer&#xff0c;\u8be5\u53c2\u6570\u5b58\u50a8\u4e86\u7f13\u51b2\u533a\u7684\u97f3\u9891\u91c7\u6837\u53c2\u6570\u548c\u97f3\u9891\u539f\u59cb\u6570\u636e\u3002\u901a\u8fc7QAudioBuffer::format()\u51fd\u6570\u53ef\u4ee5\u83b7\u5f97\u97f3\u9891\u683c\u5f0f\u53c2\u6570\u3002<\/p>\n<p>QAudioFormat audioFormat&#061;buffer.format();<\/p>\n<p>buffer.format()\u8fd4\u56de\u4e00\u4e2aQAudioFormat\u7c7b\u578b\u7684\u53d8\u91cf&#xff0c;\u5b58\u50a8\u4e86\u97f3\u9891\u7684\u683c\u5f0f\u53c2\u6570\u4fe1\u606f\u3002\u5982\u679c\u8981\u4f7f\u7528\u97f3\u9891\u7684\u539f\u59cb\u6570\u636e&#xff0c;\u9700\u8981\u5bf9\u8fd9\u4e9b\u53c2\u6570\u6709\u6240\u4e86\u89e3&#xff0c;\u7ed3\u5408\u539f\u4e66\u7684\u56fe15-2\u663e\u793a\u7684\u5185\u5bb9\u5bf9QAudioFormat\u7684\u4e00\u4e9b\u51fd\u6570\u8868\u793a\u7684\u53c2\u6570\u4f5c\u89e3\u91ca\u3002<\/p>\n<ul>\n<li>\n<p>channelCount()\u8fd4\u56de\u97f3\u9891\u6570\u636e\u7684\u5b9e\u9645\u901a\u9053\u6570&#xff0c;\u4e0e\u524d\u9762\u7684\u97f3\u9891\u8bbe\u7f6e\u7684\u901a\u9053\u6570\u4e00\u81f4\u3002<\/p>\n<\/li>\n<li>\n<p>sampleSize()\u8fd4\u56de\u91c7\u6837\u70b9\u4f4d\u6570&#xff0c;\u662f\u6307\u4e00\u4e2a\u91c7\u6837\u6570\u636e\u70b9\u7684\u91cf\u5316\u4f4d\u6570&#xff0c;\u4e00\u822c\u67098\u4f4d\u300116\u4f4d\u548c32\u4f4d\u3002\u4f4d\u6570\u8d8a\u591a&#xff0c;\u58f0\u97f3\u7684\u5206\u8fa8\u7387\u8d8a\u9ad8&#xff0c;\u4fdd\u771f\u5ea6\u4e5f\u8d8a\u9ad8&#xff0c;\u4e00\u822c16\u4f4d\u5373\u53ef\u8fbe\u5230CD\u7684\u97f3\u9891\u8d28\u91cf\u3002<\/p>\n<\/li>\n<li>\n<p>sampleRate()\u8fd4\u56de\u5b9e\u9645\u7684\u91c7\u6837\u9891\u7387&#xff0c;\u4e00\u822c\u7b49\u4e8e\u6216\u5927\u4e8e\u97f3\u9891\u8f93\u5165\u8bbe\u7f6e\u7684\u91c7\u6837\u7387&#xff0c;\u4e5f\u4f1a\u6839\u636e\u8bbe\u7f6e\u7684\u8d28\u91cf\u8981\u6c42\u81ea\u52a8\u8bbe\u7f6e\u5b9e\u9645\u7684\u91c7\u6837\u7387\u3002<\/p>\n<\/li>\n<li>\n<p>sampleType()\u8fd4\u56de\u91c7\u6837\u70b9\u683c\u5f0f&#xff0c;\u662f\u6307\u4e00\u4e2a\u91c7\u6837\u70b9\u5f97\u7528\u4ec0\u4e48\u7c7b\u578b\u7684\u6570\u636e\u6765\u8868\u793a&#xff0c;\u6709\u65e0\u7b26\u53f7\u6574\u578b&#xff08;UnSignedInt&#xff09;\u3001\u6709\u7b26\u53f7\u6574\u578b&#xff08;SignedInt&#xff09;\u548c\u6d6e\u70b9\u6570&#xff08;Float&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>byteOrder()\u8fd4\u56de\u5b57\u8282\u5e8f&#xff0c;\u5206\u4e3a\u5927\u7aef\u5b57\u8282\u5e8f\u548c\u5c0f\u7aef\u5b57\u8282\u5e8f\u3002<\/p>\n<\/li>\n<li>\n<p>codec()\u8fd4\u56de\u5b9e\u9645\u7684\u7f16\u7801\u65b9\u5f0f\u3002<\/p>\n<\/li>\n<li>\n<p>bytesPerFrame()\u8fd4\u56de\u6bcf\u5e27\u5b57\u8282\u6570&#xff0c;\u4e0d\u540c\u97f3\u9891\u7f16\u7801\u683c\u5f0f\u7684\u5e27\u7684\u5b9a\u4e49\u4e0d\u4e00\u6837&#xff0c;PCM&#xff08;Pulse Code Modulation&#xff0c;\u8109\u51b2\u7f16\u7801\u8c03\u5236&#xff09;\u7f16\u7801\u7684\u4e00\u5e27\u5c31\u662f\u5404\u4e2a\u901a\u9053\u7684\u4e00\u6b21\u91c7\u6837\u6570\u636e\u3002<\/p>\n<\/li>\n<\/ul>\n<p>QAudioBuffer\u8fd8\u6709\u5176\u4ed6\u4e00\u4e9b\u51fd\u6570\u6765\u8bf4\u660e\u7f13\u51b2\u533a\u6570\u636e\u7684\u4fe1\u606f&#xff0c;\u7ed3\u5408\u539f\u4e66\u7684\u56fe15-2\u5bf9\u8fd9\u4e9b\u53c2\u6570\u8fdb\u884c\u89e3\u91ca\u5982\u4e0b\u3002<\/p>\n<ul>\n<li>\n<p>frameCount()\u8fd4\u56de\u5e27\u6570&#xff0c;\u5bf9\u4e8ePCM\u683c\u5f0f\u7f16\u7801\u7684\u97f3\u9891\u6570\u636e&#xff0c;\u4e00\u5e27\u5c31\u662f\u4e00\u6b21\u91c7\u6837\u70b9&#xff0c;\u8fd9\u4e2a\u51fd\u6570\u8fd4\u56de\u4e86\u7f13\u51b2\u533a\u4e2d\u6570\u636e\u70b9\u7684\u5e27\u6570&#xff0c;\u5982320\u5e27\u3002<\/p>\n<\/li>\n<li>\n<p>sampleCount()\u8fd4\u56de\u91c7\u6837\u6570&#xff0c;\u91c7\u6837\u6570&#061;\u5e27\u6570*\u901a\u9053\u6570&#xff0c;\u56e0\u4e3a\u662f2\u4e2a\u901a\u9053&#xff0c;\u6240\u4ee5\u91c7\u6837\u6570\u4e3a640\u3002<\/p>\n<\/li>\n<li>\n<p>byteCount()\u8fd4\u56de\u7f13\u51b2\u533a\u5b57\u8282\u6570&#xff0c;\u5b57\u8282\u6570&#061;\u91c7\u6837\u6570*\u91c7\u6837\u5b57\u8282\u6570&#xff0c;\u56e0\u4e3a\u91c7\u6837\u70b9\u4f4d\u6570\u4f4d8\u4f4d&#xff0c;\u53731\u4e2a\u5b57\u8282&#xff0c;\u6240\u4ee5\u7f13\u51b2\u533a\u5b57\u8282\u6570\u4e3a640\u3002<\/p>\n<\/li>\n<li>\n<p>duration()\u8fd4\u56de\u7f13\u51b2\u533a\u65f6\u957f&#xff0c;\u65f6\u957f\u7531\u5e27\u6570\u548c\u91c7\u6837\u9891\u7387\u51b3\u5b9a&#xff0c;\u56fe\u4e2d\u7684\u7f13\u51b2\u533a\u65f6\u957f\u4e3a40 ms\u3002\u56e0\u4e3a\u5e27\u6570\u4e3a320&#xff0c;\u91c7\u6837\u9891\u7387\u4e3a8000 Hz&#xff0c;\u6240\u4ee5\u65f6\u957f\u4e3a&#xff1a;<\/p>\n<\/li>\n<\/ul>\n<p>QAudioBuffer::data()\u51fd\u6570\u8fd4\u56de\u7f13\u51b2\u533a\u5b58\u50a8\u7684\u97f3\u9891\u7684\u539f\u59cb\u6570\u636e&#xff0c;\u83b7\u53d6\u8fd9\u4e9b\u539f\u59cb\u6570\u636e&#xff0c;\u5c31\u53ef\u4ee5\u5bf9\u6570\u636e\u8fdb\u884c\u5206\u6790\u6216\u5904\u7406&#xff0c;\u5982\u8fdb\u884c\u8bed\u97f3\u8bc6\u522b\u5fc5\u987b\u5148\u83b7\u5f97\u8fd9\u4e9b\u97f3\u9891\u539f\u59cb\u6570\u636e\u3002<\/p>\n<p>\u4f7f\u7528QAudioRecorder\u8fdb\u884c\u97f3\u9891\u8f93\u5165\u65f6&#xff0c;\u7531\u4e8e\u8bbe\u7f6e\u7684\u91c7\u96c6\u53c2\u6570\u4e0d\u540c&#xff0c;\u5982\u8981\u6c42\u97f3\u9891\u8d28\u91cf\u4e0d\u540c\u65f6&#xff0c;\u5e95\u5c42\u7684\u97f3\u9891\u91c7\u6837\u53c2\u6570\u4f1a\u81ea\u52a8\u8c03\u6574\u3002\u4e0e\u56fe15-2\u4e2d\u7684\u8bbe\u7f6e\u76f8\u4f3c&#xff0c;\u53ea\u662f\u5c06\u97f3\u9891\u7f16\u7801\u8d28\u91cf\u8bbe\u7f6e\u4e3a\u6700\u9ad8\u8d28\u91cf&#xff0c;\u5f55\u97f3\u65f6\u7f13\u51b2\u533a\u7684\u4fe1\u606f\u5c31\u53d1\u751f\u8f83\u5927\u7684\u53d8\u5316&#xff0c;\u5982\u539f\u4e66\u7684\u56fe15-3\u6240\u793a\u3002\u56fe\u4e2d\u53ef\u4ee5\u770b\u5230\u7f13\u51b2\u533a\u7684\u91c7\u6837\u5b57\u957f\u53d8\u4e3a\u4e8616\u4f4d&#xff0c;\u91c7\u6837\u7387\u53d8\u4e3a\u4e8696000 Hz&#xff0c;\u6bcf\u5e27\u5b57\u8282\u6570\u53d8\u4e3a\u4e864\u5b57\u8282\u3002<\/p>\n<p>\u6240\u4ee5\u5728\u91c7\u7528QAudioBuffer::data()\u8bfb\u53d6\u539f\u59cb\u6570\u636e\u65f6&#xff0c;\u9700\u8981\u6839\u636eQAudioBuffer::format()\u8fd4\u56de\u7684\u683c\u5f0f\u53c2\u6570\u4ee5\u53ca\u7f13\u51b2\u533a\u5e27\u6570\u3001\u91c7\u6837\u6570\u7b49\u53c2\u6570\u624d\u80fd\u6b63\u786e\u8bfb\u53d6\u539f\u59cb\u6570\u636e&#xff0c;\u8fd9\u5b9e\u73b0\u8d77\u6765\u6bd4\u8f83\u590d\u6742&#xff0c;\u672c\u4f8b\u5c31\u4e0d\u6f14\u793a\u539f\u59cb\u6570\u636e\u7684\u8bfb\u53d6\u4e86\u3002<\/p>\n<h4>15.3.2\u3000\u4f7f\u7528QAudioInput\u83b7\u53d6\u97f3\u9891\u8f93\u5165<\/h4>\n<h5>1&#xff0e;QAudioInput\u83b7\u53d6\u97f3\u9891\u8f93\u5165\u529f\u80fd\u6982\u8ff0<\/h5>\n<p>QAudioInput\u7c7b\u63d0\u4f9b\u4e86\u63a5\u6536\u97f3\u9891\u8bbe\u5907\u8f93\u5165\u6570\u636e\u7684\u63a5\u53e3&#xff0c;\u521b\u5efaQAudioInput\u5bf9\u8c61\u5b9e\u4f8b\u65f6&#xff0c;\u9700\u8981\u7528\u4e24\u4e2a\u53c2\u6570&#xff0c;\u4e00\u4e2a\u662fQAudioDeviceInfo\u7c7b\u8868\u793a\u7684\u97f3\u9891\u8bbe\u5907&#xff0c;\u4e00\u4e2a\u662fQAudioFormat\u8868\u793a\u7684\u97f3\u9891\u8f93\u5165\u683c\u5f0f\u3002QAudioInput::start()\u51fd\u6570\u5f00\u59cb\u97f3\u9891\u6570\u636e\u8f93\u5165\u65f6&#xff0c;\u9700\u8981\u6307\u5b9a\u4e00\u4e2a\u6d41\u8bbe\u5907\u63a5\u6536\u8f93\u5165\u7684\u97f3\u9891\u6570\u636e&#xff0c;\u5982\u53ef\u4ee5\u6307\u5b9a\u4e00\u4e2aQFile\u8868\u793a\u7684\u6587\u4ef6\u3002<\/p>\n<p>QAudioInput\u4e0eQaudioRecorder\u7684\u4e0d\u540c\u4e4b\u5904\u5982\u4e0b\u3002<\/p>\n<ul>\n<li>\n<p>QAudioInput\u521b\u5efa\u65f6\u6307\u5b9a\u7684QaudioFormat\u5c06\u76f4\u63a5\u4f5c\u7528\u4e8e\u97f3\u9891\u8f93\u5165\u8bbe\u5907&#xff0c;\u4e5f\u5c31\u662f\u97f3\u9891\u8f93\u5165\u7684\u6570\u636e\u5c06\u76f4\u63a5\u6309\u7167\u8bbe\u7f6e\u7684\u53c2\u6570\u8fdb\u884c\u91c7\u6837&#xff0c;\u800cQAudioRecorder\u4e0d\u80fd\u76f4\u63a5\u63a7\u5236\u91c7\u6837\u5b57\u957f\u3001\u91c7\u6837\u70b9\u7c7b\u578b\u7b49\u5e95\u5c42\u53c2\u6570\u3002<\/p>\n<\/li>\n<li>\n<p>QAudioInput::start(QIODevice *device)\u6307\u5b9a\u4e00\u4e2aQIODevice\u8bbe\u5907\u4f5c\u4e3a\u6570\u636e\u8f93\u51fa\u5bf9\u8c61&#xff0c;\u53ef\u4ee5\u662f\u6587\u4ef6&#xff0c;\u4e5f\u53ef\u4ee5\u662f\u5176\u4ed6\u4eceQIODevice\u7ee7\u627f\u7684\u7c7b\u3002\u5982\u4eceQIODevice\u7ee7\u627f\u4e00\u4e2a\u7c7b&#xff0c;\u5bf9\u8f93\u5165\u7684\u7f13\u51b2\u533a\u6570\u636e\u8fdb\u884c\u5904\u7406&#xff0c;\u800c\u4e0d\u662f\u4fdd\u5b58\u5230\u6587\u4ef6\u3002\u800cQAudioRecorder\u53ea\u80fd\u6307\u5b9a\u6587\u4ef6\u4f5c\u4e3a\u4fdd\u5b58\u5bf9\u8c61\u3002\u6240\u4ee5&#xff0c;QAudioInput\u53ef\u4ee5\u5b9e\u73b0\u66f4\u52a0\u5e95\u5c42\u7684\u97f3\u9891\u8f93\u5165\u63a7\u5236\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u539f\u4e66\u7684\u56fe15-4\u662f\u4f7f\u7528QAudioInput\u5b9e\u73b0\u7684\u4e00\u4e2a\u97f3\u9891\u6570\u636e\u8f93\u5165\u5e76\u5b9e\u65f6\u663e\u793a\u539f\u59cb\u4fe1\u53f7\u6ce2\u5f62\u7684\u5b9e\u4f8b\u7a0b\u5e8fsamp15_4\u7684\u8fd0\u884c\u754c\u9762\u3002<\/p>\n<p>\u56fe15-4\u5de6\u4fa7\u663e\u793a\u7684\u662f\u7528QAudioDeviceInfo\u7c7b\u83b7\u53d6\u7684\u97f3\u9891\u8bbe\u5907&#xff0c;\u4ee5\u53ca\u8bbe\u5907\u652f\u6301\u7684\u5404\u79cd\u53c2\u6570&#xff0c;\u5355\u51fb\u201c\u6d4b\u8bd5\u97f3\u9891\u8bbe\u7f6e\u201d\u53ef\u4ee5\u5224\u65ad\u97f3\u9891\u8bbe\u5907\u662f\u5426\u652f\u6301\u6240\u8bbe\u7f6e\u7684\u91c7\u96c6\u914d\u7f6e\u3002\u4e3a\u4e86\u66f4\u65b9\u4fbf\u8bfb\u53d6\u539f\u59cb\u6570\u636e&#xff0c;\u5728\u5f00\u59cb\u91c7\u96c6\u65f6\u91c7\u7528\u56fa\u5b9a\u7684\u8bbe\u7f6e&#xff0c;\u53738000Hz\u30011\u901a\u9053\u30018\u4f4d\u3001\u65e0\u7b26\u53f7\u6574\u6570\u3002<\/p>\n<p>\u7a97\u53e3\u53f3\u4fa7\u662f\u4e00\u4e2aQChart\u7ec4\u4ef6&#xff0c;\u91c7\u7528QLineSeries\u4f5c\u4e3a\u663e\u793a\u5e8f\u5217\u3002\u5f00\u59cb\u91c7\u96c6\u540e&#xff0c;\u4ece\u7f13\u51b2\u533a\u8bfb\u53d6\u7684\u6570\u636e\u5c06\u5b9e\u65f6\u663e\u793a\u5728\u56fe\u8868\u4e0a\u3002<\/p>\n<h5>2&#xff0e;\u4e3b\u7a97\u53e3\u5b9a\u4e49\u4e0e\u521d\u59cb\u5316<\/h5>\n<p>samp15_4\u7684\u4e3b\u7a97\u53e3\u662f\u57fa\u4e8eQMainWindow\u7684\u7c7bMainWindow&#xff0c;\u7a97\u53e3\u754c\u9762\u8bbe\u8ba1\u7531UI\u8bbe\u8ba1\u5668\u5b9e\u73b0\u3002\u4e3b\u7a97\u53e3\u7c7bMainWindow\u7684\u5b9a\u4e49\u5982\u4e0b&#xff1a;<\/p>\n<p>class MainWindow : public QMainWindow<br \/>\n{<br \/>\n   Q_OBJECT<br \/>\nprivate:<br \/>\n   const qint64  displayPointsCount&#061;4000;<br \/>\n   QLineSeries  *lineSeries;\/\/\u66f2\u7ebf\u5e8f\u5217<br \/>\n   QList&lt;QAudioDeviceInfo&gt; deviceList;  \/\/\u97f3\u9891\u8f93\u5165\u8bbe\u5907\u5217\u8868<br \/>\n   QAudioDeviceInfo   curDevice;\/\/\u5f53\u524d\u8f93\u5165\u8bbe\u5907<br \/>\n   QmyDisplayDevice   *displayDevice; \/\/\u7528\u4e8e\u663e\u793a\u7684IODevice<br \/>\n   QAudioInput       *audioInput;\/\/\u97f3\u9891\u8f93\u5165\u8bbe\u5907<br \/>\n   QString  SampleTypeString(QAudioFormat::SampleType sampleType);<br \/>\n   QString  ByteOrderString(QAudioFormat::Endian endian);<br \/>\npublic:<br \/>\n   explicit  MainWindow(QWidget *parent &#061; 0);<br \/>\n   ~MainWindow();<br \/>\nprivate slots:<br \/>\n\/\/\u81ea\u5b9a\u4e49\u69fd\u51fd\u6570<br \/>\n   void   on_IODevice_UpdateBlockSize(qint64 blockSize);<br \/>\nprivate:<br \/>\n   Ui::MainWindow *ui;<br \/>\n};<\/p>\n<p>\u8fd9\u91cc\u5b9a\u4e49\u4e86\u8f83\u591a\u7684\u79c1\u6709\u53d8\u91cf&#xff0c;\u5176\u4e2dQmyDisplayDevice\u662f\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u4eceQIODevice\u7ee7\u627f\u7684\u7c7b&#xff0c;\u7528\u4e8e\u8bfb\u53d6\u97f3\u9891\u8f93\u5165\u7f13\u51b2\u533a\u7684\u6570\u636e&#xff0c;\u5e76\u5728\u56fe\u8868\u4e0a\u663e\u793a\u3002\u5176\u5177\u4f53\u5b9e\u73b0\u5728\u540e\u9762\u4ecb\u7ecd\u3002<\/p>\n<p>MainWindow\u7684\u6784\u9020\u51fd\u6570\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),<br \/>\n   ui(new Ui::MainWindow)<br \/>\n{<br \/>\n   ui-&gt;setupUi(this);<br \/>\n   setCentralWidget(ui-&gt;splitter);<br \/>\n\/\/\u521b\u5efa\u663e\u793a\u56fe\u8868<br \/>\n   QChart *chart &#061; new QChart;<br \/>\n   chart-&gt;setTitle(&#034;\u97f3\u9891\u8f93\u5165\u539f\u59cb\u4fe1\u53f7&#034;);<br \/>\n   ui-&gt;chartView-&gt;setChart(chart);<br \/>\n   lineSeries&#061; new QLineSeries(); \/\/\u5e8f\u5217<br \/>\n   chart-&gt;addSeries(lineSeries);<\/p>\n<p>   QValueAxis *axisX &#061; new QValueAxis;  \/\/\u5750\u6807\u8f74<br \/>\n   axisX-&gt;setRange(0, displayPointsCount); \/\/chart\u663e\u793a4000\u4e2a\u91c7\u6837\u70b9\u6570\u636e<br \/>\n   axisX-&gt;setLabelFormat(&#034;%g&#034;);<br \/>\n   axisX-&gt;setTitleText(&#034;Samples&#034;);<br \/>\n   QValueAxis *axisY &#061; new QValueAxis;  \/\/\u5750\u6807\u8f74<br \/>\n   axisY-&gt;setRange(0, 256); \/\/ UnSingedInt\u91c7\u6837&#xff0c;\u6570\u636e\u8303\u56f40-255<br \/>\n   axisY-&gt;setTitleText(&#034;Audio level&#034;);<\/p>\n<p>   chart-&gt;setAxisX(axisX, lineSeries);<br \/>\n   chart-&gt;setAxisY(axisY, lineSeries);<br \/>\n   chart-&gt;legend()-&gt;hide();<\/p>\n<p>   ui-&gt;comboDevices-&gt;clear();<br \/>\n   deviceList&#061;QAudioDeviceInfo::availableDevices(QAudio::AudioInput);<br \/>\n   for(int i&#061;0;i&lt;deviceList.count();i&#043;&#043;)<br \/>\n   {<br \/>\n      QAudioDeviceInfo device&#061;deviceList.at(i);<br \/>\n      ui-&gt;comboDevices-&gt;addItem(device.deviceName());<br \/>\n    }<\/p>\n<p>   if (deviceList.size()&gt;0)<br \/>\n   {<br \/>\n     ui-&gt;comboDevices-&gt;setCurrentIndex(0);<br \/>\n     curDevice &#061;deviceList.at(0);\/\/<br \/>\n   }<br \/>\n   else<br \/>\n   {<br \/>\n      ui-&gt;actStart-&gt;setEnabled(false);<br \/>\n      ui-&gt;actDeviceTest-&gt;setEnabled(false);<br \/>\n      ui-&gt;groupBoxDevice-&gt;setTitle(&#034;\u652f\u6301\u7684\u97f3\u9891\u8f93\u5165\u8bbe\u7f6e(\u65e0\u8bbe\u5907)&#034;);<br \/>\n   }<br \/>\n}<\/p>\n<p>\u6784\u9020\u51fd\u6570\u521b\u5efa\u4e86\u7528\u4e8e\u56fe\u8868\u663e\u793a\u7684QChart\u5bf9\u8c61chart&#xff0c;\u521b\u5efa\u4e86QLineSeries\u7c7b\u578b\u7684\u5e8f\u5217lineSeries&#xff0c;\u521b\u5efa\u4e86X\u548cY\u5750\u6807\u8f74&#xff1b;\u5176X\u8f74\u7684\u8303\u56f4\u7b49\u4e8e0\u5230\u663e\u793a\u7684\u6570\u636e\u70b9\u7684\u603b\u65704000&#xff0c;Y\u8f74\u7684\u8303\u56f4\u662f0\u81f3256&#xff0c;\u91c7\u75288\u4f4d\u65e0\u7b26\u53f7\u6574\u6570&#xff0c;\u91c7\u6837\u6570\u636e\u8303\u56f4\u662f0\u81f3255\u3002<\/p>\n<p>QAudioDeviceInfo::availableDevices(QAudio::AudioInput)\u53ef\u4ee5\u83b7\u53d6\u97f3\u9891\u8f93\u5165\u8bbe\u5907\u5217\u8868&#xff0c;\u8bbe\u5907\u540d\u79f0\u88ab\u6dfb\u52a0\u5230\u7a97\u53e3\u4e0a\u7684comboDevices\u4e0b\u62c9\u5217\u8868\u6846\u91cc\u3002<\/p>\n<h5>3&#xff0e;\u97f3\u9891\u8f93\u5165\u8bbe\u5907\u652f\u6301\u7684\u683c\u5f0f<\/h5>\n<p>\u5728\u4e3b\u7a97\u53e3\u7684\u6784\u9020\u51fd\u6570\u4e2d&#xff0c;\u5411comboDevices\u4e0b\u62c9\u5217\u8868\u6846\u4e2d\u6dfb\u52a0\u4e86\u7cfb\u7edf\u6240\u6709\u7684\u97f3\u9891\u8f93\u5165\u8bbe\u5907\u3002\u5728\u4e0b\u62c9\u5217\u8868\u6846\u91cc\u9009\u62e9\u4e00\u4e2a\u8bbe\u5907\u65f6&#xff0c;\u53d1\u5c04currentIndexChanged(int index)\u4fe1\u53f7&#xff0c;\u5728\u5176\u69fd\u51fd\u6570\u91cc\u83b7\u53d6\u8bbe\u5907\u652f\u6301\u7684\u5404\u79cd\u97f3\u9891\u8f93\u5165\u53c2\u6570&#xff0c;\u5305\u62ec\u652f\u6301\u7684\u97f3\u9891\u7f16\u7801\u3001\u91c7\u6837\u7387\u3001\u901a\u9053\u6570\u3001\u91c7\u6837\u70b9\u7c7b\u578b\u548c\u91c7\u6837\u70b9\u5927\u5c0f\u7b49&#xff0c;\u4ee5\u6b64\u66f4\u65b0\u7a97\u53e3\u4e0a\u7684\u7ec4\u4ef6\u663e\u793a\u3002<\/p>\n<p>void MainWindow::on_comboDevices_currentIndexChanged(int index)<br \/>\n{\/\/\u9009\u62e9\u97f3\u9891\u8f93\u5165\u8bbe\u5907<br \/>\n  curDevice &#061;deviceList.at(index);\/\/\u5f53\u524d\u97f3\u9891\u8bbe\u5907<br \/>\n  ui-&gt;comboCodec-&gt;clear(); \/\/\u652f\u6301\u7684\u97f3\u9891\u7f16\u7801<br \/>\n  QStringList codecs &#061; curDevice.supportedCodecs();<br \/>\n  for (int i &#061; 0; i &lt; codecs.size(); &#043;&#043;i)<br \/>\n   ui-&gt;comboCodec-&gt;addItem(codecs.at(i));<\/p>\n<p>  ui-&gt;comboSampleRate-&gt;clear(); \/\/\u652f\u6301\u7684\u91c7\u6837\u7387<br \/>\n  QList&lt;int&gt; sampleRate &#061; curDevice.supportedSampleRates();<br \/>\n  for (int i &#061; 0; i &lt; sampleRate.size(); &#043;&#043;i)<br \/>\n   ui-&gt;comboSampleRate-&gt;addItem(QString(&#034;%1&#034;).arg(sampleRate.at(i)));<\/p>\n<p>  ui-&gt;comboChannels-&gt;clear();\/\/\u652f\u6301\u7684\u901a\u9053\u6570<br \/>\n  QList&lt;int&gt; Channels &#061; curDevice.supportedChannelCounts();<br \/>\n  for (int i &#061; 0; i &lt; Channels.size(); &#043;&#043;i)<br \/>\n   ui-&gt;comboChannels-&gt;addItem(QString(&#034;%1&#034;).arg(Channels.at(i)));<\/p>\n<p>  ui-&gt;comboSampleTypes-&gt;clear(); \/\/\u652f\u6301\u7684\u91c7\u6837\u70b9\u7c7b\u578b<br \/>\n  QList&lt;QAudioFormat::SampleType&gt; sampleTypes &#061; curDevice.supportedSampleTypes();<br \/>\n  for (int i &#061; 0; i &lt; sampleTypes.size(); &#043;&#043;i)<br \/>\n   ui-&gt;comboSampleTypes-&gt;addItem(SampleTypeString(sampleTypes.at(i)), QVariant(sampleTypes.at(i)));<\/p>\n<p>  ui-&gt;comboSampleSizes-&gt;clear();\/\/\u91c7\u6837\u70b9\u5927\u5c0f<br \/>\n  QList&lt;int&gt; sampleSizes &#061; curDevice.supportedSampleSizes();<br \/>\n  for (int i &#061; 0; i &lt; sampleSizes.size(); &#043;&#043;i)<br \/>\n   ui-&gt;comboSampleSizes-&gt;addItem(QString(&#034;%1&#034;).arg(sampleSizes.at(i)));<\/p>\n<p>  ui-&gt;comboByteOrder-&gt;clear();\/\/\u5b57\u8282\u5e8f<br \/>\n  QList&lt;QAudioFormat::Endian&gt; endians &#061; curDevice.supportedByteOrders();<br \/>\n  for (int i &#061; 0; i &lt; endians.size(); &#043;&#043;i)<br \/>\n   ui-&gt;comboByteOrder-&gt;addItem(ByteOrderString(endians.at(i)));<br \/>\n}<\/p>\n<p>QString MainWindow::SampleTypeString(QAudioFormat::SampleType sampleType)<br \/>\n{\/\/\u5c06QAudioFormat::SampleType\u7c7b\u578b\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32<br \/>\n   QString result(&#034;Unknown&#034;);<br \/>\n   switch (sampleType) {<br \/>\n   case QAudioFormat::SignedInt:<br \/>\n      result &#061; &#034;SignedInt&#034;;      break;<br \/>\n   case QAudioFormat::UnSignedInt:<br \/>\n      result &#061; &#034;UnSignedInt&#034;;     break;<br \/>\n   case QAudioFormat::Float:<br \/>\n      result &#061; &#034;Float&#034;;         break;<br \/>\n   case QAudioFormat::Unknown:<br \/>\n      result &#061; &#034;Unknown&#034;;<br \/>\n   }<br \/>\n   return result;<br \/>\n}<\/p>\n<p>QString MainWindow::ByteOrderString(QAudioFormat::Endian endian)<br \/>\n{ \/\/\u5c06QAudioFormat::Endian  \u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32<br \/>\n  if (endian&#061;&#061;QAudioFormat::LittleEndian)<br \/>\n   return &#034;LittleEndian&#034;;<br \/>\n  else if (endian&#061;&#061;QAudioFormat::BigEndian)<br \/>\n   return &#034;BigEndian&#034;;<br \/>\n  else<br \/>\n   return &#034;Unknown&#034;;<br \/>\n}<\/p>\n<p>\u521b\u5efa\u4e00\u4e2aQAudioInput\u5bf9\u8c61\u65f6\u9700\u8981\u4f20\u9012\u4e00\u4e2aQAudioFormat\u7c7b\u578b\u4f5c\u4e3a\u53c2\u6570&#xff0c;\u7528\u4e8e\u6307\u5b9a\u97f3\u9891\u8f93\u5165\u914d\u7f6e&#xff0c;\u800c\u97f3\u9891\u8bbe\u5907\u662f\u5426\u652f\u6301\u8fd9\u4e9b\u914d\u7f6e\u9700\u8981\u8fdb\u884c\u6d4b\u8bd5\u3002\u7a97\u53e3\u4e0a\u7684\u201c\u6d4b\u8bd5\u97f3\u9891\u8bbe\u7f6e\u201d\u6309\u94ae\u53ef\u4ee5\u8fdb\u884c\u6d4b\u8bd5&#xff0c;\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_actDeviceTest_triggered()<br \/>\n{\/\/\u6d4b\u8bd5\u97f3\u9891\u8f93\u5165\u8bbe\u5907\u662f\u5426\u652f\u6301\u9009\u62e9\u7684\u8bbe\u7f6e<br \/>\n  QAudioFormat settings;<br \/>\n  settings.setCodec(ui-&gt;comboCodec-&gt;currentText());<br \/>\n  settings.setSampleRate(ui-&gt;comboSampleRate-&gt;currentText().toInt());<br \/>\n  settings.setChannelCount(ui-&gt;comboChannels-&gt;currentText().toInt());<br \/>\n  settings.setSampleType(QAudioFormat::SampleType(<br \/>\n        ui-&gt;comboSampleTypes-&gt;currentData().toInt()));<br \/>\n  settings.setSampleSize(ui-&gt;comboSampleSizes-&gt;currentText().toInt());<br \/>\n  if (ui-&gt;comboByteOrder-&gt;currentText()&#061;&#061;&#034;LittleEndian&#034;)<br \/>\n   settings.setByteOrder(QAudioFormat::LittleEndian);<br \/>\n  else<br \/>\n   settings.setByteOrder(QAudioFormat::BigEndian);<\/p>\n<p>  if (curDevice.isFormatSupported(settings))<br \/>\n   QMessageBox::information(this,&#034;\u97f3\u9891\u6d4b\u8bd5&#034;,&#034;\u6d4b\u8bd5\u6210\u529f&#xff0c;\u8f93\u5165\u8bbe\u5907\u652f\u6301\u6b64\u8bbe\u7f6e&#034;);<br \/>\n  else<br \/>\n   QMessageBox::critical(this,&#034;\u97f3\u9891\u6d4b\u8bd5&#034;,&#034;\u6d4b\u8bd5\u5931\u8d25&#xff0c;\u8f93\u5165\u8bbe\u5907\u4e0d\u652f\u6301\u6b64\u8bbe\u7f6e&#034;);<br \/>\n}<\/p>\n<p>QAudioFormat\u7c7b\u5bf9\u8c61settings\u4ece\u754c\u9762\u4e0a\u5404\u4e2a\u7ec4\u4ef6\u83b7\u53d6\u8bbe\u7f6e&#xff0c;\u5305\u62ec\u7f16\u7801\u683c\u5f0f\u3001\u91c7\u6837\u7387\u3001\u901a\u9053\u6570\u7b49&#xff0c;\u7136\u540e\u7528QAudioDeviceInfo::isFormatSupported()\u51fd\u6570\u6d4b\u8bd5\u662f\u5426\u652f\u6301\u6b64\u8bbe\u7f6e&#xff1b;\u5982\u679c\u4e0d\u652f\u6301&#xff0c;\u8fd8\u53ef\u4ee5\u4f7f\u7528QAudioDeviceInfo\u7684nearestFormat()\u51fd\u6570\u83b7\u53d6\u6700\u63a5\u8fd1\u7684\u914d\u7f6e\u3002<\/p>\n<h5>4&#xff0e;\u5f00\u59cb\u97f3\u9891\u8f93\u5165<\/h5>\n<p>\u5355\u51fb\u7a97\u53e3\u5de5\u5177\u680f\u4e0a\u201c\u5f00\u59cb\u201d\u6309\u94ae&#xff0c;\u5373\u53ef\u5f00\u59cb\u97f3\u9891\u6570\u636e\u8f93\u5165&#xff0c;\u5176\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_actStart_triggered()<br \/>\n{\/\/\u5f00\u59cb\u97f3\u9891\u8f93\u5165<br \/>\n   QAudioFormat defaultAudioFormat; \/\/\u7f3a\u7701\u683c\u5f0f<br \/>\n   defaultAudioFormat.setSampleRate(8000);<br \/>\n   defaultAudioFormat.setChannelCount(1);<br \/>\n   defaultAudioFormat.setSampleSize(8);<br \/>\n   defaultAudioFormat.setCodec(&#034;audio\/pcm&#034;);<br \/>\n   defaultAudioFormat.setByteOrder(QAudioFormat::LittleEndian);<br \/>\n   defaultAudioFormat.setSampleType(QAudioFormat::UnSignedInt);<br \/>\n   if (!curDevice.isFormatSupported(defaultAudioFormat))<br \/>\n   {<br \/>\n      QMessageBox::critical(this,&#034;\u6d4b\u8bd5&#034;,&#034;\u6d4b\u8bd5\u5931\u8d25&#xff0c;\u8f93\u5165\u8bbe\u5907\u4e0d\u652f\u6301\u6b64\u8bbe\u7f6e&#034;);<br \/>\n      return;<br \/>\n   }<\/p>\n<p>   audioInput &#061; new QAudioInput(curDevice,defaultAudioFormat, this);<br \/>\n   audioInput-&gt;setBufferSize(displayPointsCount);<br \/>\n\/\/ \u63a5\u6536\u97f3\u9891\u8f93\u5165\u6570\u636e\u7684\u6d41\u8bbe\u5907<br \/>\n   displayDevice &#061; new QmyDisplayDevice(lineSeries, displayPointsCount,this);<br \/>\n   connect(displayDevice,SIGNAL(updateBlockSize(qint64)),<br \/>\n          this,SLOT(on_IODevice_UpdateBlockSize(qint64)));<br \/>\n   displayDevice-&gt;open(QIODevice::WriteOnly); <\/p>\n<p>   audioInput-&gt;start(displayDevice);<br \/>\n   ui-&gt;actStart-&gt;setEnabled(false);<br \/>\n   ui-&gt;actStop-&gt;setEnabled(true);<br \/>\n}<\/p>\n<p>\u4e3a\u4e86\u4fbf\u4e8e\u89e3\u6790\u97f3\u9891\u8f93\u5165\u7684\u539f\u59cb\u6570\u636e&#xff0c;\u97f3\u9891\u8f93\u5165\u7684\u914d\u7f6e\u91c7\u7528\u56fa\u5b9a\u7684\u7b80\u5355\u65b9\u5f0f&#xff0c;\u800c\u4e0d\u662f\u6839\u636e\u754c\u9762\u4e0a\u7684\u8bbe\u7f6e\u8fdb\u884c\u914d\u7f6e\u3002\u97f3\u9891\u8f93\u5165\u914d\u7f6e\u56fa\u5b9a\u4e3a8000 Hz\u91c7\u6837\u7387\u30011\u4e2a\u901a\u9053\u30018\u4f4d\u65e0\u7b26\u53f7\u6574\u6570\u3001audio\/pcm\u7f16\u7801\u548c\u5c0f\u7aef\u5b57\u8282\u5e8f\u3002<\/p>\n<p>\u521b\u5efaQAudioInput\u7c7b\u5bf9\u8c61audioInput\u65f6&#xff0c;\u4f20\u9012defaultAudioFormat\u548ccurDevice\u4f5c\u4e3a\u53c2\u6570&#xff0c;\u5e76\u8bbe\u7f6e\u7f13\u51b2\u533a\u5927\u5c0f\u4e3adisplayPointsCount&#xff08;\u7b49\u4e8e4000&#xff09;\u3002<\/p>\n<p>audioInput &#061; new QAudioInput(curDevice,defaultAudioFormat, this);<br \/>\naudioInput-&gt;setBufferSize(displayPointsCount);<\/p>\n<p>\u4f7f\u7528setBufferSize\u8bbe\u7f6e\u7684\u7f13\u51b2\u533a&#xff0c;\u9700\u8981\u5728\u8c03\u7528start()\u4e4b\u524d\u8bbe\u7f6e\u624d\u6709\u6548\u3002\u7f13\u51b2\u533a\u7684\u5927\u5c0f\u5927\u4e8e\u6bcf\u6b21\u66f4\u65b0\u8f93\u5165\u7684\u539f\u59cb\u6570\u636e\u5757\u7684\u5927\u5c0f&#xff0c;\u5728\u539f\u4e66\u7684\u56fe15-4\u4e2d\u53ef\u89c1\u7f13\u51b2\u533a\u5927\u5c0f\u4e3a4000&#xff0c;\u800c\u6bcf\u6b21\u66f4\u65b0\u7684\u539f\u59cb\u6570\u636e\u7684\u6570\u636e\u5b57\u8282\u6570\u4e3a800\u3002<\/p>\n<p>\u968f\u540e\u7a0b\u5e8f\u521b\u5efa\u4e00\u4e2aQmyDisplayDevice\u7c7b\u578b\u7684IO\u8bbe\u5907displayDevice&#xff0c;\u8fd9\u4e2a\u7c7b\u5b9e\u73b0\u4e86\u6d41\u8bbe\u5907\u7684writeData()\u51fd\u6570&#xff0c;\u7528\u4e8e\u8bfb\u53d6\u97f3\u9891\u8f93\u5165\u7684\u6570\u636e\u5e76\u5728\u66f2\u7ebf\u4e0a\u663e\u793a\u3002\u5176\u6784\u9020\u51fd\u6570\u63a5\u6536lineSeries\u548cdisplayPointsCount\u4f5c\u4e3a\u53c2\u6570\u3002\u518d\u5c06displayDevice\u7684\u4fe1\u53f7updateBlockSize()\u4e0e\u4e00\u4e2a\u81ea\u5b9a\u4e49\u69fd\u51fd\u6570\u5173\u8054&#xff0c;\u7136\u540e\u5c06displayDevice\u4ee5\u53ea\u5199\u65b9\u5f0f\u6253\u5f00\u3002<\/p>\n<p>\u6700\u540e\u8c03\u7528QAudioInput::start()\u51fd\u6570\u5f00\u59cb\u97f3\u9891\u8f93\u5165&#xff0c;\u4ee5displayDevice\u4f5c\u4e3aIO\u6d41\u8bbe\u5907\u3002<\/p>\n<p>audioInput-&gt;start(displayDevice);<\/p>\n<p>\u81ea\u5b9a\u4e49\u69fd\u51fd\u6570on_IODevice_UpdateBlockSize()\u7528\u4e8e\u663e\u793a\u7f13\u51b2\u533a\u5927\u5c0f\u548c\u6570\u636e\u5757\u5927\u5c0f&#xff0c;\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_IODevice_UpdateBlockSize(qint64 blockSize)<br \/>\n{\/\/\u663e\u793a\u7f13\u51b2\u533a\u5927\u5c0f\u548c\u6570\u636e\u5757\u5927\u5c0f<br \/>\n   ui-&gt;LabBufferSize-&gt;setText(QString::asprintf(<br \/>\n         &#034;QAudioInput::bufferSize()&#061;%d&#034;,audioInput-&gt;bufferSize()));<br \/>\n   ui-&gt;LabBlockSize-&gt;setText(<br \/>\n             QString(&#034;IODevice\u6570\u636e\u5757\u5b57\u8282\u6570&#061;%1&#034;).arg(blockSize));<br \/>\n}<\/p>\n<h5>5&#xff0e;\u6d41\u8bbe\u5907QmyDisplayDevice\u7684\u529f\u80fd\u5b9e\u73b0<\/h5>\n<p>\u4f7f\u7528QAudioInput\u83b7\u53d6\u97f3\u9891\u8f93\u5165\u6570\u636e\u65f6&#xff0c;\u9700\u8981\u4f7f\u7528\u4e00\u4e2aQIODevice\u7c7b\u578b\u7684\u8bbe\u5907\u4f5c\u4e3a\u6d41\u8f93\u51fa\u8bbe\u5907&#xff0c;\u4e00\u822c\u91c7\u7528QFile\u53ef\u4ee5\u5c06\u6570\u636e\u8bb0\u5f55\u5230\u6587\u4ef6\u3002\u672c\u4f8b\u4e2d\u4f7f\u7528\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u7c7bQmyDisplayDevice&#xff0c;\u7528\u4e8e\u83b7\u53d6\u97f3\u9891\u8f93\u5165\u6570\u636e\u5e76\u5728\u66f2\u7ebf\u4e0a\u5b9e\u65f6\u663e\u793a\u3002<\/p>\n<p>QmyDisplayDevice\u7c7b\u7684\u5b9a\u4e49\u5982\u4e0b&#xff1a;<\/p>\n<p>#include  &lt;QtCharts&gt;<br \/>\n#include  &lt;QIODevice&gt;<br \/>\nclass QmyDisplayDevice : public QIODevice<br \/>\n{<br \/>\n   Q_OBJECT<br \/>\npublic:<br \/>\n   explicit QmyDisplayDevice(QXYSeries * series, qint64 pointsCount,QObject *parent &#061; 0);<br \/>\nprotected:<br \/>\n   qint64 readData(char * data, qint64 maxSize);<br \/>\n   qint64 writeData(const char * data, qint64 maxSize);<br \/>\nprivate:<br \/>\n   QXYSeries *m_series;<br \/>\n   qint64  range&#061;4000;<br \/>\nsignals:<br \/>\n   void  updateBlockSize(qint64 blockSize);<br \/>\n};<\/p>\n<p>\u56e0\u4e3aQmyDisplayDevice\u7c7b\u4eceQIODevice\u7ee7\u627f&#xff0c;\u6240\u4ee5\u5177\u6709\u6d41\u6570\u636e\u8bfb\u5199\u529f\u80fd\u3002\u91cd\u65b0\u5b9e\u73b0\u7684readData()\u548cwriteData()\u662f\u5b9e\u73b0\u6d41\u6570\u636e\u8bfb\u5199\u529f\u80fd\u7684\u3002<\/p>\n<p>\u5b9a\u4e49\u4e86m_series\u548crange\u4e24\u4e2a\u79c1\u6709\u53d8\u91cf\u3002m_series\u662f\u7528\u4e8e\u56fe\u8868\u66f2\u7ebf\u663e\u793a\u7684QXYSeries\u5e8f\u5217&#xff0c;range\u7f3a\u7701\u503c\u4e3a4000&#xff0c;\u662f\u5e8f\u5217\u6700\u591a\u663e\u793a\u7684\u6570\u636e\u70b9\u6570\u3002\u6784\u9020\u51fd\u6570\u91cc\u63a5\u6536series\u548cpointsCount\u5bf9\u4e0a\u8ff0\u4e24\u4e2a\u53d8\u91cf\u8fdb\u884c\u521d\u59cb\u5316\u3002<\/p>\n<p>QmyDisplayDevice\u7c7b\u7684\u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>QmyDisplayDevice::QmyDisplayDevice(QXYSeries * series, qint64 pointsCount, QObject *parent) :   QIODevice(parent)<br \/>\n{\/\/ \u6784\u9020\u51fd\u6570<br \/>\n   m_series&#061; series;<br \/>\n   range&#061;pointsCount;<br \/>\n}<\/p>\n<p>qint64 QmyDisplayDevice::readData(char * data, qint64 maxSize)<br \/>\n{\/\/ \u6d41\u7684\u8bfb\u64cd\u4f5c,\u4e0d\u5904\u7406<br \/>\n   Q_UNUSED(data)<br \/>\n   Q_UNUSED(maxSize)<br \/>\n   return -1;<br \/>\n}<br \/>\nqint64 QmyDisplayDevice::writeData(const char * data, qint64 maxSize)<br \/>\n{ \/\/\u8bfb\u53d6\u6570\u636e\u5757\u5185\u7684\u6570\u636e&#xff0c;\u66f4\u65b0\u5230\u5e8f\u5217<br \/>\n   QVector&lt;QPointF&gt; oldPoints &#061; m_series-&gt;pointsVector();<br \/>\n   QVector&lt;QPointF&gt; points; \/\/\u4e34\u65f6<br \/>\n   if (oldPoints.count() &lt; range)<br \/>\n   { \/\/m_series\u5e8f\u5217\u7684\u6570\u636e\u672a\u6ee14000\u70b9&#xff0c;<br \/>\n      points &#061; m_series-&gt;pointsVector();<br \/>\n   }<br \/>\n   else<br \/>\n   {\/\/\u5c06\u539f\u6765maxSize\u81f34000\u7684\u6570\u636e\u70b9\u524d\u79fb<br \/>\n      for (int i &#061; maxSize; i &lt; oldPoints.count(); i&#043;&#043;)<br \/>\n        points.append(QPointF(i &#8211; maxSize, oldPoints.at(i).y()));<br \/>\n   }<\/p>\n<p>   qint64 size &#061; points.count();<br \/>\n   for (int k &#061; 0; k &lt; maxSize; k&#043;&#043;) \/\/\u6570\u636e\u5757\u5185\u7684\u6570\u636e\u586b\u5145\u5e8f\u5217\u7684\u5c3e\u90e8<br \/>\n      points.append(QPointF(k &#043; size, (quint8)data[k]));<\/p>\n<p>   m_series-&gt;replace(points);<br \/>\n   emit updateBlockSize(maxSize);<br \/>\n   return maxSize;<br \/>\n}<\/p>\n<p>QmyDisplayDevice\u65e0\u9700\u5b9e\u73b0\u6d41\u7684\u8bfb\u64cd\u4f5c&#xff0c;\u6240\u4ee5readData()\u51fd\u6570\u4e0d\u505a\u4ec0\u4e48\u5904\u7406&#xff0c;\u91cd\u70b9\u662f\u6d41\u7684\u5199\u64cd\u4f5cwriteData()\u51fd\u6570\u7684\u5b9e\u73b0\u3002<\/p>\n<p>writeData()\u4f20\u9012\u8fdb\u6765\u7684\u53c2\u6570data\u662f\u6570\u636e\u5757\u7684\u6307\u9488&#xff0c;maxSize\u662f\u6570\u636e\u5757\u7684\u5b57\u8282\u6570&#xff0c;\u8fd9\u662f\u9700\u8981\u8bfb\u53d6\u51fa\u6765\u7684\u97f3\u9891\u8f93\u5165\u6570\u636e\u3002<\/p>\n<p>\u7531\u4e8e\u97f3\u9891\u8f93\u5165\u914d\u7f6e\u4e3a1\u901a\u90538\u4f4d\u65e0\u7b26\u53f7\u7684\u6574\u6570\u91c7\u6837&#xff0c;\u6240\u4ee5\u4e00\u4e2a\u6570\u636e\u70b9\u5c31\u662f\u4e00\u4e2a\u5b57\u8282\u7684\u6570\u636e\u3002<\/p>\n<p>\u663e\u793a\u5e8f\u5217m_series\u5b58\u50a8\u7684\u663e\u793a\u6570\u636e\u70b9\u4e2a\u6570\u9650\u5b9a\u4e3a4000\u4e2a\u70b9&#xff0c;\u5927\u4e8emaxSize&#xff08;\u6b64\u4f8b\u4e2d\u4e3a800&#xff09;&#xff0c;\u6240\u4ee5\u5bf9\u4e8e\u5e8f\u5217\u7684\u6570\u636e\u70b9\u7684\u66f4\u65b0\u91c7\u7528FIFO&#xff08;\u5148\u5165\u5148\u51fa&#xff09;\u7684\u65b9\u5f0f\u3002<\/p>\n<p>\u66f4\u65b0\u4e34\u65f6\u6570\u636e\u70b9\u5411\u91cfpoints&#xff0c;\u91c7\u7528\u5e8f\u5217\u7684replace()\u51fd\u6570\u66ff\u6362\u5e8f\u5217\u539f\u6709\u7684\u6570\u636e\u70b9\u5411\u91cf&#xff0c;\u662f\u6700\u5feb\u7684\u65b9\u5f0f\u3002<\/p>\n<p>writeData()\u51fd\u6570\u6700\u540e\u53d1\u5c04\u4fe1\u53f7updateBlockSize(maxSize)&#xff0c;\u7528\u4e8e\u4e3b\u7a97\u53e3\u7684\u5173\u8054\u69fd\u51fd\u6570on_IODevice_UpdateBlockSize()\u5219\u663e\u793a\u6570\u636e\u5757\u7684\u5927\u5c0f\u3002<\/p>\n<h3>15.4\u3000\u89c6\u9891\u64ad\u653e<\/h3>\n<p>\u4f7f\u7528QMediaPlayer\u53ef\u4ee5\u8fdb\u884c\u89c6\u9891\u6587\u4ef6\u89e3\u7801&#xff0c;\u89c6\u9891\u64ad\u653e\u5fc5\u987b\u5c06\u89c6\u9891\u5e27\u5728\u67d0\u4e2a\u754c\u9762\u7ec4\u4ef6\u4e0a\u663e\u793a&#xff0c;\u6709QVideoWidget\u548cQGraphicsVideoItem\u4e24\u79cd\u89c6\u9891\u663e\u793a\u7ec4\u4ef6&#xff0c;\u4e5f\u53ef\u4ee5\u4ece\u8fd9\u4e24\u4e2a\u7c7b\u7ee7\u627f&#xff0c;\u81ea\u5b9a\u4e49\u89c6\u9891\u663e\u793a\u7ec4\u4ef6\u3002<\/p>\n<p>QMediaPlayer\u4e5f\u53ef\u4ee5\u7ed3\u5408QMediaPlaylist\u5b9e\u73b0\u89c6\u9891\u6587\u4ef6\u5217\u8868\u64ad\u653e\u3002<\/p>\n<h4>15.4.1\u3000\u5728QVideoWidget\u4e0a\u64ad\u653e\u89c6\u9891<\/h4>\n<h5>1&#xff0e;\u89c6\u9891\u64ad\u653e\u5668\u5b9e\u4f8b\u7a0b\u5e8f<\/h5>\n<p>QVideoWidget\u662f\u7528\u4e8e\u663e\u793a\u89c6\u9891\u7684\u754c\u9762\u7ec4\u4ef6&#xff0c;\u8981\u5728\u9879\u76ee\u4e2d\u4f7f\u7528QVideoWidget&#xff0c;\u9700\u8981\u5728\u9879\u76ee\u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4e0b\u9762\u4e00\u884c\u8bed\u53e5&#xff1a;<\/p>\n<p>****Qt &#043;&#061; multimediawidgets<\/p>\n<p>\u4f7f\u7528QMediaPlayer\u548cQVideoWidget\u5b9e\u73b0\u7684\u4e00\u4e2a\u89c6\u9891\u64ad\u653e\u5668\u5b9e\u4f8b\u7a0b\u5e8fsamp15_5\u8fd0\u884c\u65f6\u754c\u9762\u5982\u539f\u4e66\u7684\u56fe15-5\u6240\u793a\u3002\u8be5\u7a0b\u5e8f\u6ca1\u6709\u4f7f\u7528QMediaPlaylist&#xff0c;\u53ea\u64ad\u653e\u5355\u4e2a\u6587\u4ef6\u3002<\/p>\n<p>\u754c\u9762\u7684\u4e3b\u4f53\u90e8\u5206\u662f\u4e00\u4e2aQmyVideoWidget\u7c7b\u7ec4\u4ef6&#xff0c;\u662f\u4eceQVideoWidget\u7ee7\u627f\u7684\u81ea\u5b9a\u4e49\u89c6\u9891\u663e\u793a\u7ec4\u4ef6&#xff0c;\u91cd\u8f7d\u4e86mousePressEvent()\u4e8b\u4ef6&#xff0c;\u9f20\u6807\u5355\u51fb\u53ef\u4ee5\u6682\u505c\u6216\u7ee7\u7eed\u64ad\u653e&#xff1b;\u91cd\u8f7d\u4e86keyPressEvent()\u4e8b\u4ef6&#xff0c;\u5728\u5168\u5c4f\u72b6\u6001\u4e0b\u6309ESC\u952e\u53ef\u4ee5\u9000\u51fa\u5168\u5c4f\u3002\u539f\u59cb\u7684QVideoWidget\u7c7b\u6ca1\u6709\u8fd9\u4e9b\u529f\u80fd\u3002<\/p>\n<h5>2&#xff0e;\u4e3b\u7a97\u53e3\u8bbe\u8ba1<\/h5>\n<p>\u4e3b\u7a97\u53e3\u662f\u57fa\u4e8eQMainWindow\u7684\u7c7bMainWindow&#xff0c;\u91c7\u7528UI\u8bbe\u8ba1\u5668\u8bbe\u8ba1\u754c\u9762\u3002\u5728\u8bbe\u8ba1\u89c6\u9891\u663e\u793a\u7ec4\u4ef6\u65f6&#xff0c;\u5728\u7a97\u4f53\u4e0a\u653e\u7f6e\u4e00\u4e2aQWidget\u7ec4\u4ef6&#xff0c;\u7136\u540e\u63d0\u5347\u4e3aQmyVideoWidget\u7c7b\u3002<\/p>\n<p>\u4e3b\u7a97\u53e3\u529f\u80fd\u4e3b\u8981\u662f\u4f7f\u7528\u4e00\u4e2aQMediaPlayer\u7ec4\u4ef6\u64ad\u653e\u5355\u4e2a\u89c6\u9891\u6587\u4ef6\u3002\u5a92\u4f53\u64ad\u653e\u7c7bQMediaPlayer\u7684\u529f\u80fd\u572815.2\u8282\u4ecb\u7ecd\u97f3\u9891\u64ad\u653e\u65f6\u5df2\u7ecf\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/p>\n<p>MainWindow\u7c7b\u5b9a\u4e49\u5982\u4e0b&#xff08;\u5ffd\u7565\u4e86\u81ea\u52a8\u751f\u6210\u7684\u754c\u9762\u7ec4\u4ef6\u7684\u69fd\u51fd\u6570\u5b9a\u4e49&#xff09;&#xff1a;<\/p>\n<p>class MainWindow : public QMainWindow<br \/>\n{<br \/>\n   Q_OBJECT<br \/>\nprivate:<br \/>\n   QMediaPlayer   *player;\/\/\u89c6\u9891\u64ad\u653e\u5668<br \/>\n   QString  durationTime;<br \/>\n   QString  positionTime;<br \/>\npublic:<br \/>\n   explicit MainWindow(QWidget *parent &#061; 0);<br \/>\n   ~MainWindow();<br \/>\nprivate slots:<br \/>\n\/\/\u81ea\u5b9a\u4e49\u69fd\u51fd\u6570<br \/>\n   void onStateChanged(QMediaPlayer::State state);<br \/>\n   void onDurationChanged(qint64 duration);<br \/>\n   void onPositionChanged(qint64 position);<br \/>\nprivate:<br \/>\n   Ui::MainWindow *ui;<br \/>\n};<\/p>\n<p>MainWindow\u7c7b\u7684\u529f\u80fd\u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b&#xff0c;\u53ea\u64ad\u653e\u5355\u4e2a\u6587\u4ef6&#xff0c;\u6bd415.2\u8282\u7684\u97f3\u9891\u64ad\u653e\u5668\u529f\u80fd\u7b80\u5355&#xff0c;\u6240\u4ee5\u5177\u4f53\u4ee3\u7801\u7684\u529f\u80fd\u8fd9\u91cc\u4e0d\u518d\u8d58\u8ff0\u3002<\/p>\n<p>MainWindow::MainWindow(QWidget *parent) :   QMainWindow(parent),<br \/>\n   ui(new Ui::MainWindow)<br \/>\n{\/\/\u6784\u9020\u51fd\u6570<br \/>\n   ui-&gt;setupUi(this);<br \/>\n   player &#061; new QMediaPlayer(this);\/\/\u521b\u5efa\u89c6\u9891\u64ad\u653e\u5668<br \/>\n   player-&gt;setNotifyInterval(2000);\/\/\u4fe1\u606f\u66f4\u65b0\u5468\u671f2000 ms<br \/>\n   player-&gt;setVideoOutput(ui-&gt;videoWidget);\/\/\u89c6\u9891\u663e\u793a\u7ec4\u4ef6<br \/>\n   ui-&gt;videoWidget-&gt;setMediaPlayer(player);\/\/\u8bbe\u7f6e\u663e\u793a\u7ec4\u4ef6\u7684\u5173\u8054\u64ad\u653e\u5668<br \/>\n   connect(player,SIGNAL(stateChanged(QMediaPlayer::State)),<br \/>\n         this, SLOT(onStateChanged(QMediaPlayer::State)));<br \/>\n   connect(player,SIGNAL(positionChanged(qint64)),<br \/>\n         this, SLOT(onPositionChanged(qint64)));<br \/>\n   connect(player,SIGNAL(durationChanged(qint64)),<br \/>\n         this, SLOT(onDurationChanged(qint64)));<br \/>\n}<br \/>\nvoid MainWindow::onStateChanged(QMediaPlayer::State state)<br \/>\n{\/\/\u64ad\u653e\u5668\u72b6\u6001\u53d8\u5316<br \/>\n   ui-&gt;btnPlay-&gt;setEnabled(!(state&#061;&#061;QMediaPlayer::PlayingState));<br \/>\n   ui-&gt;btnPause-&gt;setEnabled(state&#061;&#061;QMediaPlayer::PlayingState);<br \/>\n   ui-&gt;btnStop-&gt;setEnabled(state&#061;&#061;QMediaPlayer::PlayingState);<br \/>\n}<br \/>\nvoid MainWindow::onDurationChanged(qint64 duration)<br \/>\n{\/\/\u6587\u4ef6\u65f6\u957f\u53d8\u5316<br \/>\n   ui-&gt;sliderPosition-&gt;setMaximum(duration);<br \/>\n   int   secs&#061;duration\/1000;\/\/\u79d2<br \/>\n   int   mins&#061;secs\/60; \/\/\u5206\u949f<br \/>\n   secs&#061;secs % 60;\/\/\u4f59\u6570\u79d2<br \/>\n   durationTime&#061;QString::asprintf(&#034;%d:%d&#034;,mins,secs);<br \/>\n   ui-&gt;LabRatio-&gt;setText(positionTime&#043;&#034;\/&#034;&#043;durationTime);<br \/>\n}<br \/>\nvoid MainWindow::onPositionChanged(qint64 position)<br \/>\n{\/\/\u6587\u4ef6\u64ad\u653e\u4f4d\u7f6e\u53d8\u5316<br \/>\n   if (ui-&gt;sliderPosition-&gt;isSliderDown())<br \/>\n      return; \/\/\u5982\u679c\u6b63\u5728\u62d6\u52a8\u6ed1\u6761&#xff0c;\u9000\u51fa<br \/>\n   ui-&gt;sliderPosition-&gt;setSliderPosition(position);<br \/>\n   int   secs&#061;position\/1000;\/\/\u79d2<br \/>\n   int   mins&#061;secs\/60; \/\/\u5206\u949f<br \/>\n   secs&#061;secs % 60;\/\/\u4f59\u6570\u79d2<br \/>\n   positionTime&#061;QString::asprintf(&#034;%d:%d&#034;,mins,secs);<br \/>\n   ui-&gt;LabRatio-&gt;setText(positionTime&#043;&#034;\/&#034;&#043;durationTime);<br \/>\n}<br \/>\nvoid MainWindow::on_btnAdd_clicked()<br \/>\n{\/\/\u6253\u5f00\u6587\u4ef6<br \/>\n   QString curPath&#061;QDir::homePath();\/\/\u83b7\u53d6\u7cfb\u7edf\u5f53\u524d\u76ee\u5f55<br \/>\n   QString dlgTitle&#061;&#034;\u9009\u62e9\u89c6\u9891\u6587\u4ef6&#034;; \/\/\u5bf9\u8bdd\u6846\u6807\u9898<br \/>\n   QString filter&#061;&#034;wmv\u6587\u4ef6(*.wmv);;mp4\u6587\u4ef6(*.mp4);;\u6240\u6709\u6587\u4ef6(*.*)&#034;;<br \/>\n   QString aFile&#061;QFileDialog::getOpenFileName(this, dlgTitle, curPath, filter);<br \/>\n   if (aFile.isEmpty())<br \/>\n     return;<br \/>\n   QFileInfo   fileInfo(aFile);<br \/>\n   ui-&gt;LabCurMedia-&gt;setText(fileInfo.fileName());<br \/>\n   player-&gt;setMedia(QUrl::fromLocalFile(aFile));\/\/\u8bbe\u7f6e\u64ad\u653e\u6587\u4ef6<br \/>\n   player-&gt;play();<br \/>\n}<br \/>\nvoid MainWindow::on_btnPlay_clicked()<br \/>\n{\/\/\u64ad\u653e<br \/>\n   player-&gt;play();<br \/>\n}<br \/>\nvoid MainWindow::on_btnPause_clicked()<br \/>\n{\/\/\u6682\u505c<br \/>\n   player-&gt;pause();<br \/>\n}<br \/>\nvoid MainWindow::on_btnStop_clicked()<br \/>\n{\/\/\u505c\u6b62<br \/>\n   player-&gt;stop();<br \/>\n}<br \/>\nvoid MainWindow::on_sliderVolumn_valueChanged(int value)<br \/>\n{\/\/\u8c03\u8282\u97f3\u91cf<br \/>\n   player-&gt;setVolume(value);<br \/>\n}<br \/>\nvoid MainWindow::on_btnSound_clicked()<br \/>\n{\/\/\u9759\u97f3\u6309\u94ae<br \/>\n   bool mute&#061;player-&gt;isMuted();<br \/>\n   player-&gt;setMuted(!mute);<br \/>\n   if (mute)<br \/>\n      ui-&gt;btnSound-&gt;setIcon(QIcon(&#034;:\/images\/images\/volumn.bmp&#034;));<br \/>\n   else<br \/>\n      ui-&gt;btnSound-&gt;setIcon(QIcon(&#034;:\/images\/images\/mute.bmp&#034;));<br \/>\n}<br \/>\nvoid MainWindow::on_sliderPosition_valueChanged(int value)<br \/>\n{\/\/\u64ad\u653e\u4f4d\u7f6e<br \/>\n   player-&gt;setPosition(value);<br \/>\n}<br \/>\nvoid MainWindow::on_pushButton_clicked()<br \/>\n{\/\/\u5168\u5c4f\u6309\u94ae<br \/>\n   ui-&gt;videoWidget-&gt;setFullScreen(true);<br \/>\n}<\/p>\n<h5>3&#xff0e;\u81ea\u5b9a\u4e49\u89c6\u9891\u663e\u793a\u7ec4\u4ef6QmyVideoWidget<\/h5>\n<p>\u539f\u59cb\u7684QVideoWidget\u5728\u5168\u5c4f\u540e\u65e0\u6cd5\u6309Esc\u952e\u9000\u51fa\u5168\u5c4f\u72b6\u6001&#xff0c;\u4e3a\u4e86\u5b9e\u73b0\u6309\u952e\u548c\u9f20\u6807\u63a7\u5236\u529f\u80fd&#xff0c;\u4eceQVideoWidget\u7ee7\u627f\u4e86\u4e00\u4e2a\u7c7bQmyVideoWidget&#xff0c;\u5176\u5b9a\u4e49\u5982\u4e0b&#xff1a;<\/p>\n<p>class QmyVideoWidget : public QVideoWidget<br \/>\n{<br \/>\nprivate:<br \/>\n   QMediaPlayer   *thePlayer;<br \/>\nprotected:<br \/>\n   void  keyPressEvent(QKeyEvent *event);<br \/>\n   void  mousePressEvent(QMouseEvent *event);<br \/>\npublic:<br \/>\n   QmyVideoWidget(QWidget *parent &#061; Q_NULLPTR);<br \/>\n   void   setMediaPlayer(QMediaPlayer *player);<br \/>\n};<\/p>\n<p>\u79c1\u6709\u53d8\u91cfthePlayer\u662f\u5173\u8054\u7684\u89c6\u9891\u64ad\u653e\u5668&#xff0c;\u5728\u5f00\u59cb\u64ad\u653e\u4e4b\u524d\u7531\u4e3b\u7a97\u53e3\u7a0b\u5e8f\u8c03\u7528setMediaPlayer()\u8fdb\u884c\u8bbe\u7f6e&#xff0c;\u4ee5\u4fbf\u5728QmyVideoWidget\u91cc\u5bf9\u64ad\u653e\u5668\u8fdb\u884c\u63a7\u5236\u3002<\/p>\n<p>\u4e0b\u9762\u662fQmyVideoWidget\u7c7b\u7684\u5b9e\u73b0\u4ee3\u7801&#xff1a;<\/p>\n<p>void QmyVideoWidget::keyPressEvent(QKeyEvent *event)<br \/>\n{\/\/\u6309\u952e\u4e8b\u4ef6&#xff0c;ESC\u9000\u51fa\u5168\u5c4f\u72b6\u6001<br \/>\n   if ((event-&gt;key() &#061;&#061; Qt::Key_Escape)&amp;&amp;(isFullScreen()))<br \/>\n   {<br \/>\n      setFullScreen(false);<br \/>\n      event-&gt;accept();<br \/>\n      QVideoWidget::keyPressEvent(event);<br \/>\n   }<br \/>\n}<br \/>\nvoid QmyVideoWidget::mousePressEvent(QMouseEvent *event)<br \/>\n{\/\/\u9f20\u6807\u4e8b\u4ef6&#xff0c;\u5355\u51fb\u63a7\u5236\u6682\u505c\u548c\u7ee7\u7eed\u64ad\u653e<br \/>\n   if (event-&gt;button()&#061;&#061;Qt::LeftButton)<br \/>\n   {<br \/>\n      if (thePlayer-&gt;state()&#061;&#061;QMediaPlayer::PlayingState)<br \/>\n        thePlayer-&gt;pause();<br \/>\n      else<br \/>\n        thePlayer-&gt;play();<br \/>\n   }<br \/>\n   QVideoWidget::mousePressEvent(event);<br \/>\n}<br \/>\nvoid QmyVideoWidget::setMediaPlayer(QMediaPlayer *player)<br \/>\n{\/\/\u8bbe\u7f6e\u64ad\u653e\u5668<br \/>\n   thePlayer&#061;player;<br \/>\n}<\/p>\n<h4>15.4.2\u3000\u5728QGraphicsVideoItem\u4e0a\u64ad\u653e\u89c6\u9891<\/h4>\n<p>QMediaPlayer\u89e3\u7801\u7684\u89c6\u9891\u8fd8\u53ef\u4ee5\u5728QGraphicsVideoItem\u7c7b\u7ec4\u4ef6\u4e0a\u663e\u793a\u3002QGraphicsVideoItem\u662f\u7ee7\u627f\u81eaQGraphicsItem\u7684\u7c7b&#xff0c;\u662f\u9002\u7528\u4e8eGraphics\/View\u6a21\u5f0f\u7684\u56fe\u5f62\u663e\u793a\u7ec4\u4ef6\u3002\u6240\u4ee5\u5728\u4f7f\u7528QGraphicsVideoItem\u663e\u793a\u89c6\u9891\u65f6&#xff0c;\u53ef\u4ee5\u5728\u663e\u793a\u573a\u666f\u4e2d\u548c\u5176\u4ed6\u56fe\u5f62\u7ec4\u4ef6\u7ec4\u5408\u663e\u793a&#xff0c;\u4e5f\u53ef\u4ee5\u4f7f\u7528QGraphicsItem\u7c7b\u7684\u653e\u5927\u3001\u7f29\u5c0f\u3001\u62d6\u52a8\u3001\u65cb\u8f6c\u7b49\u529f\u80fd\u3002<\/p>\n<p>\u539f\u4e66\u7684\u56fe15-6\u6240\u793a\u662f\u4f7f\u7528QMediaPlayer\u548cQGraphicsVideoItem\u64ad\u653e\u89c6\u9891\u7684\u793a\u4f8b\u7a0b\u5e8fsamp15_6\u8fd0\u884c\u65f6\u754c\u9762\u3002\u7a97\u53e3\u4e3b\u4f53\u90e8\u5206\u662f\u4e00\u4e2aQGraphicsView\u7ec4\u4ef6&#xff0c;\u5728\u8fd9\u4e2a\u56fe\u5f62\u89c6\u56fe\u4e2d\u521b\u5efa\u4e86\u4e00\u4e2aQGraphicsVideoItem\u5bf9\u8c61\u7528\u4e8e\u663e\u793a\u64ad\u653e\u7684\u89c6\u9891&#xff0c;\u8fd8\u521b\u5efa\u4e86\u4e24\u4e2a\u56fe\u5f62\u7ec4\u4ef6&#xff0c;\u8fd9\u4e9b\u7ec4\u4ef6\u90fd\u53ef\u4ee5\u62d6\u52a8\u3002<\/p>\n<p>\u4e3b\u7a97\u53e3\u6784\u9020\u51fd\u6570\u7684\u90e8\u5206\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>MainWindow::MainWindow(QWidget *parent) :   QMainWindow(parent),<br \/>\n   ui(new Ui::MainWindow)<br \/>\n{<br \/>\n   ui-&gt;setupUi(this);<br \/>\n   player &#061; new QMediaPlayer(this);<br \/>\n   player-&gt;setNotifyInterval(2000);<br \/>\n   QGraphicsScene *scene &#061; new QGraphicsScene(this);<br \/>\n   ui-&gt;graphicsView-&gt;setScene(scene);<\/p>\n<p>   videoItem &#061; new QGraphicsVideoItem;<br \/>\n   videoItem-&gt;setSize(QSizeF(360, 240));<br \/>\n   videoItem-&gt;setFlags(QGraphicsItem::ItemIsMovable<br \/>\n                | QGraphicsItem::ItemIsSelectable<br \/>\n                | QGraphicsItem::ItemIsFocusable);<br \/>\n   scene-&gt;addItem(videoItem);<br \/>\n   player-&gt;setVideoOutput(videoItem);\/\/\u8bbe\u7f6e\u89c6\u9891\u663e\u793a\u56fe\u5f62\u7ec4\u4ef6<\/p>\n<p>   connect(player,SIGNAL(stateChanged(QMediaPlayer::State)),<br \/>\n          this, SLOT(onStateChanged(QMediaPlayer::State)));<br \/>\n   connect(player,SIGNAL(positionChanged(qint64)),<br \/>\n          this, SLOT(onPositionChanged(qint64)));<br \/>\n   connect(player,SIGNAL(durationChanged(qint64)),<br \/>\n          this, SLOT(onDurationChanged(qint64)));<br \/>\n}<\/p>\n<p>\u4ee3\u7801\u521b\u5efaQGraphicsVideoItem\u7c7b\u578b\u53d8\u91cfvideoItem&#xff0c;\u5e76\u4e14\u8bbe\u7f6e\u5176\u4e3a\u53ef\u79fb\u52a8\u3001\u53ef\u9009\u62e9\u3001\u53ef\u4ee5\u83b7\u5f97\u7126\u70b9\u3002\u8bbe\u7f6e\u89c6\u9891\u64ad\u653e\u5668player\u89c6\u9891\u8f93\u51fa\u5230videoItem\u4e0a\u663e\u793a\u3002<\/p>\n<p>\u539f\u4e66\u7684\u56fe15-6\u4e2d\u7a0b\u5e8f\u5176\u4ed6\u529f\u80fd\u7684\u5b9e\u73b0\u4e0e\u5b9e\u4f8bsamp15_5&#xff0c;\u8fd9\u91cc\u4e0d\u518d\u8d58\u8ff0\u3002<\/p>\n<h3>15.5\u3000\u6444\u50cf\u5934\u7684\u4f7f\u7528<\/h3>\n<h4>15.5.1\u3000\u6444\u50cf\u5934\u63a7\u5236\u6982\u8ff0<\/h4>\n<p>Qt\u591a\u5a92\u4f53\u6a21\u5757\u4e3a\u6444\u50cf\u5934\u63a7\u5236\u63d0\u4f9b\u4e86\u51e0\u4e2a\u7c7b&#xff0c;\u53ef\u4ee5\u7528\u4e8e\u83b7\u53d6\u6444\u50cf\u5934\u8bbe\u5907\u4fe1\u606f&#xff0c;\u901a\u8fc7\u6444\u50cf\u5934\u8fdb\u884c\u62cd\u7167\u548c\u5f55\u50cf\u3002<\/p>\n<p>&#xff08;1&#xff09;\u6444\u50cf\u5934\u8bbe\u5907\u4fe1\u606f\u7c7bQCameraInfo\u3002<\/p>\n<p>QCameraInfo\u7528\u4e8e\u83b7\u53d6\u7cfb\u7edf\u7684\u6444\u50cf\u5934\u8bbe\u5907\u4fe1\u606f&#xff0c;\u6709\u4e24\u4e2a\u9759\u6001\u51fd\u6570\u83b7\u53d6\u6444\u50cf\u5934\u8bbe\u5907&#xff1a;<\/p>\n<ul>\n<li>\n<p>QList\u3000availableCameras()&#xff0c;\u8fd4\u56deQCameraInfo\u7c7b\u7684\u5217\u8868&#xff0c;\u8868\u793a\u7cfb\u7edf\u53ef\u7528\u7684\u6444\u50cf\u5934\u8bbe\u5907\u5217\u8868&#xff1b;<\/p>\n<\/li>\n<li>\n<p>QCameraInfo\u3000defaultCamera()&#xff0c;\u8fd4\u56de\u7cfb\u7edf\u7f3a\u7701\u7684\u6444\u50cf\u5934\u8bbe\u5907\u4fe1\u606f\u3002<\/p>\n<\/li>\n<\/ul>\n<p>QCameraInfo\u6709\u51e0\u4e2a\u51fd\u6570\u8868\u793a\u6444\u50cf\u5934\u4fe1\u606f&#xff1a;<\/p>\n<ul>\n<li>\n<p>QString\u3000description()&#xff0c;\u8fd4\u56de\u6444\u50cf\u5934\u8bbe\u5907\u63cf\u8ff0&#xff1b;<\/p>\n<\/li>\n<li>\n<p>QString\u3000deviceName()&#xff0c;\u8fd4\u56de\u6444\u50cf\u5934\u8bbe\u5907\u540d\u79f0&#xff1b;<\/p>\n<\/li>\n<li>\n<p>QCamera::Position\u3000position()&#xff0c;\u8fd4\u56de\u6444\u50cf\u5934\u7684\u4f4d\u7f6e&#xff0c;\u5982\u624b\u673a\u8bbe\u5907\u4e0a\u4e00\u822c\u6709\u4e24\u4e2a\u6444\u50cf\u5934&#xff0c;\u524d\u7f6e\u6444\u50cf\u5934\u4f4d\u7f6e\u7c7b\u578b\u4e3aQCamera::FrontFace&#xff0c;\u540e\u7f6e\u6444\u50cf\u5934\u4f4d\u7f6e\u7c7b\u578b\u4e3aQCamera::BackFace&#xff0c;\u672a\u6307\u5b9a\u4f4d\u7f6e\u7684\u662fQCamera::UnspecifiedPosition\u3002<\/p>\n<\/li>\n<\/ul>\n<p>&#xff08;2&#xff09;\u6444\u50cf\u5934\u63a7\u5236\u7c7bQCamera\u3002<\/p>\n<p>QCamera\u662f\u7528\u4e8e\u63a7\u5236\u6444\u50cf\u5934\u7684\u7c7b&#xff0c;\u521b\u5efaQCamera\u5bf9\u8c61\u65f6\u9700\u4f20\u9012\u4e00\u4e2aQCameraInfo\u5bf9\u8c61\u4f5c\u4e3a\u53c2\u6570&#xff0c;QCamera\u4e3b\u8981\u7684\u529f\u80fd\u51fd\u6570\u5305\u62ec\u4ee5\u4e0b\u51e0\u4e2a\u3002<\/p>\n<ul>\n<li>\n<p>setViewfinder()&#xff0c;\u4e3a\u6444\u50cf\u5934\u6307\u5b9a\u4e00\u4e2aQVideoWidget\u6216QGraphicsVideoItem\u5bf9\u8c61\u4f5c\u4e3a\u53d6\u666f\u5668&#xff0c;\u7528\u4e8e\u6444\u50cf\u5934\u56fe\u50cf\u9884\u89c8\u3002<\/p>\n<\/li>\n<li>\n<p>QCameraExposure\u3000*exposure()&#xff0c;\u8fd4\u56de\u7528\u4e8e\u66dd\u5149\u63a7\u5236\u7684\u5bf9\u8c61\u3002<\/p>\n<\/li>\n<li>\n<p>QCameraFocus\u3000*focus()&#xff0c;\u8fd4\u56de\u7528\u4e8e\u805a\u7126\u63a7\u5236\u7684\u5bf9\u8c61\u3002<\/p>\n<\/li>\n<li>\n<p>setCaptureMode(QCamera::CaptureModes mode)&#xff0c;\u7528\u4e8e\u8bbe\u7f6e\u6444\u50cf\u5934\u5904\u4e8e\u4e0d\u540c\u7684\u5de5\u4f5c\u6a21\u5f0f&#xff0c;QCamera::CaptureModes\u679a\u4e3e\u7c7b\u578b\u7684\u53d6\u503c\u6709&#xff1a;<\/p>\n<\/li>\n<\/ul>\n<p>QCamera::CaptureViewfinder&#xff0c;\u53d6\u666f\u5668\u6a21\u5f0f&#xff1b;<\/p>\n<p>QCamera::CaptureStillImage&#xff0c;\u6293\u53d6\u9759\u6001\u56fe\u7247\u6a21\u5f0f&#xff1b;<\/p>\n<p>QCamera::CaptureVideo&#xff0c;\u89c6\u9891\u5f55\u5236\u6a21\u5f0f\u3002<\/p>\n<ul>\n<li>bool isCaptureModeSupported(CaptureModes mode)&#xff0c;\u5224\u65ad\u6444\u50cf\u5934\u662f\u5426\u652f\u6301\u67d0\u79cd\u6293\u53d6\u6a21\u5f0f\u3002<\/li>\n<\/ul>\n<p>&#xff08;3&#xff09;\u9759\u6001\u56fe\u7247\u6293\u53d6\u7c7bQCameraImageCapture\u3002<\/p>\n<p>QCameraImageCapture\u7528\u4e8e\u63a7\u5236\u6444\u50cf\u5934\u8fdb\u884c\u9759\u6001\u56fe\u7247\u7684\u6293\u53d6\u3002<\/p>\n<p>&#xff08;4&#xff09;\u89c6\u9891\u548c\u97f3\u9891\u5f55\u5236\u7c7bQMediaRecorder\u3002<\/p>\n<p>QMediaRecorder\u901a\u8fc7\u6444\u50cf\u5934\u548c\u97f3\u9891\u8f93\u5165\u8bbe\u5907\u8fdb\u884c\u5f55\u50cf\u3002<\/p>\n<p>\u6ce8\u610f&#xff1a;\u4f7f\u7528Qt\u591a\u5a92\u4f53\u6a21\u5757\u7684\u6444\u50cf\u5934\u76f8\u5173\u7c7b\u65e0\u6cd5\u5728Windows\u5e73\u53f0\u4e0a\u8fdb\u884c\u89c6\u9891\u5f55\u5236&#xff0c;\u53ea\u80fd\u8fdb\u884c\u9759\u6001\u56fe\u7247\u6293\u53d6&#xff0c;\u4f46\u662f\u5728Linux\u5e73\u53f0\u4e0a\u53ef\u4ee5\u5b9e\u73b0\u9759\u6001\u56fe\u7247\u6293\u53d6\u548c\u89c6\u9891\u5f55\u5236\u3002\u6240\u4ee5&#xff0c;\u672c\u8282\u7684\u5b9e\u4f8b\u7a0b\u5e8f\u5728Linux\u5e73\u53f0&#xff08;64\u4f4d\u7248\u672c\u7684Ubuntu 16.04&#xff09;\u4e0a\u6d4b\u8bd5\u3002<\/p>\n<p>Qt\u591a\u5a92\u4f53\u6a21\u5757\u7684\u529f\u80fd\u5b9e\u73b0\u662f\u4f9d\u8d56\u4e8e\u5e73\u53f0\u7684\u3002\u5728Windows\u5e73\u53f0\u4e0a&#xff0c;Qt\u591a\u5a92\u4f53\u6a21\u5757\u4f9d\u8d56\u4e8e\u4e24\u4e2a\u63d2\u4ef6&#xff0c;\u4e00\u4e2a\u662f\u4f7f\u7528Microsoft DirectShow API\u7684\u63d2\u4ef6&#xff0c;DirectShow API\u5728Windows 98\u5f15\u5165&#xff0c;\u5728Windows XP\u4ee5\u540e\u5c31\u9010\u6e10\u8fc7\u65f6\u4e86&#xff1b;\u53e6\u4e00\u4e2a\u662fWindows Media Foundation&#xff08;WMF&#xff09;\u67b6\u6784\u7684\u63d2\u4ef6&#xff0c;WMF\u63d2\u4ef6\u5728Windows Vista\u5f15\u5165&#xff0c;\u7528\u4e8e\u66ff\u4ee3DirectShow API\u3002<\/p>\n<p>Qt\u4e2d\u7684WMF\u63d2\u4ef6\u76ee\u524d\u65e0\u6cd5\u63d0\u4f9b\u6444\u50cf\u5934\u652f\u6301&#xff0c;\u5bf9\u6444\u50cf\u5934\u7684\u6709\u9650\u652f\u6301\u662f\u7531DirectShow\u63d2\u4ef6\u63d0\u4f9b\u7684&#xff0c;\u76ee\u524d\u53ea\u80fd\u663e\u793a\u53d6\u666f\u5668\u548c\u6293\u53d6\u9759\u6001\u56fe\u7247&#xff0c;\u5176\u4ed6\u5927\u90e8\u5206\u529f\u80fd\u4e0d\u652f\u6301\u3002\u6240\u4ee5&#xff0c;\u76ee\u524d\u5728Windows\u5e73\u53f0\u4e0a&#xff0c;Qt\u7684\u6444\u50cf\u5934\u63a7\u5236\u4e0d\u652f\u6301\u89c6\u9891\u5f55\u5236\u529f\u80fd&#xff0c;\u4e5f\u4e0d\u652f\u6301\u5e95\u5c42\u7684\u89c6\u9891\u529f\u80fd&#xff0c;\u5982\u4f7f\u7528QVideoProbe\u76d1\u6d4b\u89c6\u9891\u5e27\u3002<\/p>\n<p>\u5bf9\u4e8e\u8fd9\u4e9b\u9650\u5236\u7684\u539f\u6587\u4ecb\u7ecd\u53ef\u4ee5\u53c2\u8003Qt\u5b98\u7f51\u4e0a\u201cQt Multimedia on Windows\u201d\u7684\u89e3\u91ca\u3002<\/p>\n<p>\u6240\u4ee5&#xff0c;\u672c\u8282\u7684\u5b9e\u4f8b\u7a0b\u5e8fsamp15_7\u572864\u4f4d\u7248\u672c\u7684Ubuntu 16.04\u684c\u9762\u7cfb\u7edf\u4e0a\u6d4b\u8bd5&#xff0c;Ubuntu\u7cfb\u7edf\u8fd0\u884c\u4e8eVirtualBox\u865a\u62df\u673a\u4e0a\u3002\u539f\u4e66\u7684\u56fe15-7\u6240\u793a\u662f\u7a0b\u5e8f\u8fd0\u884c\u65f6\u754c\u9762\u3002<\/p>\n<p>\u5de5\u5177\u680f\u4e0a\u51e0\u4e2a\u6309\u94ae\u7684\u529f\u80fd\u4e00\u76ee\u4e86\u7136&#xff0c;\u201c\u6444\u50cf\u5934\u53c2\u6570\u201d\u91cc\u663e\u793a\u6444\u50cf\u5934\u7684\u53c2\u6570&#xff0c;\u4ee5\u53ca\u5f55\u5236\u89c6\u9891\u7684\u4e00\u4e9b\u8bbe\u7f6e\u3002\u7a97\u53e3\u5de5\u4f5c\u533a\u5de6\u4fa7\u7684\u201c\u6444\u50cf\u5934\u9884\u89c8\u201d\u6846\u91cc\u663e\u793a\u6444\u50cf\u5934\u7684\u5b9e\u65f6\u56fe\u50cf\u9884\u89c8&#xff0c;\u53f3\u4fa7\u201c\u6293\u53d6\u56fe\u7247\u201d\u6846\u91cc\u663e\u793a\u6293\u53d6\u7684\u9759\u6001\u56fe\u7247\u3002<\/p>\n<h4>15.5.2\u3000\u5b9e\u4f8b\u4e3b\u7a97\u53e3\u8bbe\u8ba1\u4e0e\u521d\u59cb\u5316<\/h4>\n<p>\u5b9e\u4f8bsamp15_7\u7684\u4e3b\u7a97\u53e3\u662f\u57fa\u4e8eQMainWindow\u7684\u7c7bMainWindow&#xff0c;\u754c\u9762\u7531UI\u8bbe\u8ba1\u5668\u8bbe\u8ba1\u3002\u5728\u7a97\u53e3\u5de6\u4fa7\u201c\u6444\u50cf\u5934\u9884\u89c8\u201d\u6846\u91cc\u653e\u7f6e\u4e00\u4e2aQWidget\u7ec4\u4ef6&#xff0c;\u5e76\u63d0\u5347\u4e3aQCameraViewfinder&#xff0c;\u8fd9\u662f\u4eceQVideoWidget\u7ee7\u627f\u7684\u7c7b&#xff0c;\u4e13\u95e8\u7528\u4e8e\u6444\u50cf\u5934\u9884\u89c8\u663e\u793a\u3002\u5728\u7a97\u53e3\u53f3\u4fa7\u201c\u6293\u53d6\u56fe\u7247\u201d\u6846\u91cc\u653e\u7f6e\u4e00\u4e2aQLabel\u7ec4\u4ef6&#xff0c;\u7528\u4e8e\u663e\u793a\u6293\u53d6\u7684\u56fe\u7247\u3002<\/p>\n<p>\u7a97\u53e3\u7684\u5de5\u5177\u680f\u6309\u94ae\u7531Action\u751f\u6210&#xff0c;\u8bbe\u8ba1\u7684Action\u5217\u8868\u5982\u539f\u4e66\u7684\u56fe15-8\u6240\u793a\u3002<\/p>\n<p>\u4e3b\u7a97\u53e3\u7c7bMainWindow\u7684\u5b9a\u4e49\u5982\u4e0b&#xff08;\u7701\u7565\u4e86\u81ea\u52a8\u751f\u6210\u7684\u754c\u9762\u7ec4\u4ef6\u7684\u69fd\u51fd\u6570\u5b9a\u4e49&#xff09;&#xff1a;<\/p>\n<p>class MainWindow : public QMainWindow<br \/>\n{<br \/>\n   Q_OBJECT<br \/>\nprivate:<br \/>\n   QCamera   *curCamera&#061;Q_NULLPTR;<br \/>\n   QCameraImageCapture  *imageCapture; \/\/\u6293\u56fe<br \/>\n   QMediaRecorder    * mediaRecorder;\/\/\u5f55\u50cf<br \/>\n   QLabel   *LabCameraState;<br \/>\n   QLabel   *LabInfo;<br \/>\n   QLabel   *LabCameraMode;<br \/>\n   void   iniCamera();\/\/\u521d\u59cb\u5316<br \/>\n   void   iniImageCapture();\/\/\u521d\u59cb\u5316\u9759\u6001\u6293\u56fe<br \/>\n   void   iniVideoRecorder();\/\/\u521d\u59cb\u5316\u89c6\u9891\u5f55\u5236<br \/>\npublic:<br \/>\n   explicit MainWindow(QWidget *parent &#061; 0);<br \/>\n   ~MainWindow();<br \/>\nprivate slots:<br \/>\n\/\/QCamera\u7684\u69fd\u51fd\u6570<br \/>\n   void   on_cameraStateChanged(QCamera::State state);<br \/>\n   void   on_cameraCaptureModeChanged(QCamera::CaptureModes mode);<br \/>\n\/\/QCameraImageCapture\u7684\u69fd\u51fd\u6570<br \/>\n   void   on_imageReadyForCapture(bool ready);<br \/>\n   void   on_imageCaptured(int id, const QImage &amp;preview);<br \/>\n   void   on_imageSaved(int id, const QString &amp;fileName);<br \/>\n\/\/ QMediaRecorder\u7684\u69fd\u51fd\u6570<br \/>\n   void   on_videoStateChanged(QMediaRecorder::State state);<br \/>\n   void   on_videoDurationChanged(qint64 duration);<br \/>\nprivate:<br \/>\n   Ui::MainWindow *ui;<br \/>\n};<\/p>\n<p>\u8fd9\u91cc\u5b9a\u4e49\u4e86QCamera\u3001QCameraImageCapture\u548cQmediaRecorder 3\u4e2a\u7c7b\u578b\u7684\u79c1\u6709\u53d8\u91cf\u3002\u5b9a\u4e49\u4e863\u4e2a\u79c1\u6709\u51fd\u6570&#xff0c;\u5206\u522b\u7528\u4e8e3\u4e2a\u5bf9\u8c61\u7684\u521b\u5efa\u548c\u521d\u59cb\u5316\u3002<\/p>\n<p>\u5b9a\u4e49\u4e86\u591a\u4e2a\u69fd\u51fd\u6570&#xff0c;\u5206\u522b\u4e0e3\u4e2a\u5bf9\u8c61\u7684\u76f8\u5e94\u4fe1\u53f7\u5173\u8054\u3002<\/p>\n<p>\u4e0b\u9762\u662fMainWindow\u7684\u6784\u9020\u51fd\u6570\u7684\u4ee3\u7801&#xff1a;<\/p>\n<p>MainWindow::MainWindow(QWidget *parent) :   QMainWindow(parent),<br \/>\n   ui(new Ui::MainWindow)<br \/>\n{<br \/>\n   ui-&gt;setupUi(this);<br \/>\n   LabCameraState&#061;new QLabel(&#034;\u6444\u50cf\u5934state: &#034;);<br \/>\n   LabCameraState-&gt;setMinimumWidth(150);<br \/>\n   ui-&gt;statusBar-&gt;addWidget(LabCameraState);<br \/>\n   LabCameraMode&#061;new QLabel(&#034;\u6293\u53d6\u6a21\u5f0f: &#034;);<br \/>\n   LabCameraMode-&gt;setMinimumWidth(150);<br \/>\n   ui-&gt;statusBar-&gt;addWidget(LabCameraMode);<br \/>\n   LabInfo&#061;new QLabel(&#034;&#034;);<br \/>\n   ui-&gt;statusBar-&gt;addPermanentWidget(LabInfo);<\/p>\n<p>   QList&lt;QCameraInfo&gt; cameras &#061; QCameraInfo::availableCameras();<br \/>\n   if (cameras.size()&gt;0)<br \/>\n   {<br \/>\n      iniCamera();  \/\/\u521d\u59cb\u5316\u6444\u50cf\u5934<br \/>\n      iniImageCapture();\/\/\u521d\u59cb\u5316\u9759\u6001\u6293\u56fe<br \/>\n      iniVideoRecorder();\/\/\u521d\u59cb\u5316\u89c6\u9891\u5f55\u5236<br \/>\n      curCamera-&gt;start();<br \/>\n   }<br \/>\n}<\/p>\n<p>\u6784\u9020\u51fd\u6570\u9996\u5148\u8981\u521b\u5efa\u72b6\u6001\u680f\u4e0a\u663e\u793a\u4fe1\u606f\u7684\u6807\u7b7e&#xff0c;\u7136\u540e\u4f7f\u7528QCameraInfo\u7684\u9759\u6001\u51fd\u6570availableCameras()\u83b7\u53d6\u6444\u50cf\u5934\u5217\u8868cameras&#xff0c;\u5982\u679c\u5b58\u5728\u6444\u50cf\u5934\u8bbe\u5907&#xff0c;\u5c31\u4f9d\u6b21\u8c03\u75283\u4e2a\u521d\u59cb\u5316\u51fd\u6570\u8fdb\u884c\u521d\u59cb\u5316&#xff0c;\u7136\u540e\u6253\u5f00\u6444\u50cf\u5934\u3002<\/p>\n<h4>15.5.3\u3000QCamera\u5bf9\u8c61\u521b\u5efa\u4e0e\u63a7\u5236<\/h4>\n<p>iniCamera()\u51fd\u6570\u8fdb\u884cQCamera\u5bf9\u8c61\u7684\u521b\u5efa\u4e0e\u521d\u59cb\u5316&#xff0c;\u5728MainWindow\u7684\u6784\u9020\u51fd\u6570\u91cc\u8c03\u7528&#xff0c;\u4e0b\u9762\u662finiCamera()\u51fd\u6570\u7684\u4ee3\u7801&#xff1a;<\/p>\n<p>void MainWindow::iniCamera()<br \/>\n{\/\/  \u521b\u5efa QCamera\u5bf9\u8c61<br \/>\n   QCameraInfo curCameraInfo&#061;QCameraInfo::defaultCamera(); \/\/\u83b7\u53d6\u7f3a\u7701\u6444\u50cf\u5934<br \/>\n   ui-&gt;comboCamera-&gt;addItem(curCameraInfo.description());<br \/>\n   ui-&gt;comboCamera-&gt;setCurrentIndex(0);<\/p>\n<p>   curCamera&#061;new QCamera(curCameraInfo, this); \/\/\u521b\u5efa\u6444\u50cf\u5934\u5bf9\u8c61<br \/>\n   QCameraViewfinderSettings viewfinderSettings;<br \/>\n   viewfinderSettings.setResolution(640, 480);<br \/>\n   viewfinderSettings.setMinimumFrameRate(15.0);<br \/>\n   viewfinderSettings.setMaximumFrameRate(30.0);<br \/>\n   curCamera-&gt;setViewfinderSettings(viewfinderSettings);<br \/>\n   curCamera-&gt;setViewfinder(ui-&gt;viewFinder); \/\/\u8bbe\u7f6e\u9884\u89c8\u6846<br \/>\n   curCamera-&gt;setCaptureMode(QCamera::CaptureViewfinder);<br \/>\n\/\/\u5224\u65ad\u6444\u50cf\u5934\u662f\u5426\u652f\u6301\u6293\u56fe\u3001\u5f55\u5236\u89c6\u9891<br \/>\n   ui-&gt;checkStillImage-&gt;setChecked(<br \/>\n    curCamera-&gt;isCaptureModeSupported(QCamera::CaptureStillImage)); \/\/\u6293\u56fe<br \/>\n   ui-&gt;checkVideo-&gt;setChecked(<br \/>\n    curCamera-&gt;isCaptureModeSupported(QCamera::CaptureVideo));\/\/\u89c6\u9891\u5f55\u5236<\/p>\n<p>   connect(curCamera,SIGNAL(stateChanged(QCamera::State)),<br \/>\n         this,SLOT(on_cameraStateChanged(QCamera::State)));<br \/>\n\/\/Windows\u5e73\u53f0\u4e0a\u4e0d\u652f\u6301captureModeChanged()\u4fe1\u53f7<br \/>\n   connect(curCamera,SIGNAL(captureModeChanged(QCamera::CaptureModes)),<br \/>\n     this,SLOT(on_cameraCaptureModeChanged(QCamera::CaptureModes)));<br \/>\n}<\/p>\n<p>\u8fd9\u91cc\u7528QCameraInfo::defaultCamera()\u83b7\u53d6\u7f3a\u7701\u7684\u6444\u50cf\u5934\u8bbe\u5907&#xff0c;\u7136\u540e\u7528\u4e8e\u521b\u5efaQCamera\u5bf9\u8c61\u5b9e\u4f8bcurCamera\u3002<\/p>\n<p>QCamera::setViewfinder()\u51fd\u6570\u7528\u4e8e\u8bbe\u7f6e\u53d6\u666f\u6846\u9884\u89c8\u7ec4\u4ef6\u3002<\/p>\n<p>QCamera::setCaptureMode()\u51fd\u6570\u8bbe\u7f6e\u6444\u50cf\u5934\u7684\u6293\u53d6\u6a21\u5f0f\u3002<\/p>\n<p>\u7136\u540e\u67e5\u8be2curCamera\u662f\u5426\u652f\u6301\u6293\u56fe\u3001\u652f\u6301\u5f55\u50cf&#xff0c;\u5e76\u66f4\u65b0\u754c\u9762\u4e0a\u7684\u590d\u9009\u6846\u7684\u72b6\u6001\u3002<\/p>\n<p>\u4e3acurCamera\u7684\u4e24\u4e2a\u4fe1\u53f7\u5206\u522b\u8bbe\u7f6e\u4e86\u5173\u8054\u7684\u69fd\u51fd\u6570\u3002stateChanged()\u5728\u6444\u50cf\u5934\u72b6\u6001\u53d8\u5316\u65f6\u53d1\u5c04&#xff0c;captureModeChanged()\u5219\u5728\u6444\u50cf\u5934\u6293\u53d6\u6a21\u5f0f\u53d8\u5316\u65f6\u53d1\u5c04&#xff0c;\u4e0d\u8fc7\u5728Windows\u5e73\u53f0\u4e0a\u4e0d\u4f1a\u53d1\u5c04captureModeChanged()\u4fe1\u53f7\u3002\u8fd9\u4e24\u4e2a\u69fd\u51fd\u6570\u7684\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_cameraStateChanged(QCamera::State state)<br \/>\n{<br \/>\n  switch (state)<br \/>\n  {<br \/>\n   case QCamera::UnloadedState:<br \/>\n     LabCameraState-&gt;setText(&#034;\u6444\u50cf\u5934state: UnloadedState&#034;);   break;<br \/>\n   case QCamera::LoadedState:<br \/>\n     LabCameraState-&gt;setText(&#034;\u6444\u50cf\u5934state: LoadedState&#034;);     break;<br \/>\n   case QCamera::ActiveState:<br \/>\n     LabCameraState-&gt;setText(&#034;\u6444\u50cf\u5934state: ActiveState&#034;);<br \/>\n  }<br \/>\n  ui-&gt;actStartCamera-&gt;setEnabled(state!&#061;QCamera::ActiveState);<br \/>\n  ui-&gt;actStopCamera-&gt;setEnabled(state&#061;&#061;QCamera::ActiveState);<br \/>\n}<br \/>\nvoid MainWindow::on_cameraCaptureModeChanged(QCamera::CaptureModes mode)<br \/>\n{<br \/>\n   if (mode&#061;&#061;QCamera::CaptureStillImage)<br \/>\n      LabCameraMode-&gt;setText(&#034;\u6293\u53d6\u6a21\u5f0f: StillImage&#034;);<br \/>\n   else if (mode&#061;&#061;QCamera::CaptureVideo)<br \/>\n      LabCameraMode-&gt;setText(&#034;\u6293\u53d6\u6a21\u5f0f: Video&#034;);<br \/>\n   else<br \/>\n      LabCameraMode-&gt;setText(&#034;\u6293\u53d6\u6a21\u5f0f: Viewfinder&#034;);<br \/>\n}<\/p>\n<p>\u7a97\u53e3\u5de5\u5177\u680f\u4e0a\u7684\u201c\u5f00\u542f\u6444\u50cf\u5934\u201d\u548c\u201c\u5173\u95ed\u6444\u50cf\u5934\u201d\u4e24\u4e2a\u6309\u94ae\u63a7\u5236\u6444\u50cf\u5934\u7684\u5f00\u542f\u548c\u5173\u95ed&#xff0c;\u5176\u5173\u8054Action\u7684\u69fd\u51fd\u6570\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_actStartCamera_triggered()<br \/>\n{\/\/\u5f00\u542f\u6444\u50cf\u5934<br \/>\n   curCamera-&gt;start();<br \/>\n}<br \/>\nvoid MainWindow::on_actStopCamera_triggered()<br \/>\n{\/\/\u5173\u95ed\u6444\u50cf\u5934<br \/>\n   curCamera-&gt;stop();<br \/>\n}<\/p>\n<p>\u5f00\u542f\u548c\u5173\u95ed\u6444\u50cf\u5934\u65f6&#xff0c;QCamera\u5bf9\u8c61\u4f1a\u53d1\u5c04stateChanged()\u4fe1\u53f7\u3002\u5f00\u542f\u6444\u50cf\u5934\u4e4b\u540e&#xff0c;\u6444\u50cf\u5934\u72b6\u6001\u4e3aQCamera::ActiveState&#xff0c;\u5173\u95ed\u4e4b\u540e\u72b6\u6001\u4f1a\u53d8\u6210QCamera::LoadedState\u3002<\/p>\n<h4>15.5.4\u3000QCameraImageCapture\u6293\u53d6\u9759\u6001\u56fe\u7247<\/h4>\n<p>QCameraImageCapture\u7c7b\u5bf9\u8c61imageCapture\u7528\u4e8e\u901a\u8fc7\u6444\u50cf\u5934\u6293\u53d6\u9759\u6001\u56fe\u7247&#xff0c;iniImageCapture()\u51fd\u6570\u7528\u4e8e\u521b\u5efaimageCapture\u5e76\u8fdb\u884c\u521d\u59cb\u5316\u8bbe\u7f6e&#xff0c;MainWindow\u6784\u9020\u51fd\u6570\u8c03\u7528\u6b64\u51fd\u6570\u3002IniImageCapture()\u51fd\u6570\u7684\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::iniImageCapture()<br \/>\n{\/\/\u521b\u5efa QCameraImageCapture\u5bf9\u8c61<br \/>\n   imageCapture &#061; new QCameraImageCapture(curCamera,this);<br \/>\n   imageCapture-&gt;setBufferFormat(QVideoFrame::Format_Jpeg); \/\/\u7f13\u51b2\u533a\u683c\u5f0f<br \/>\n   imageCapture-&gt;setCaptureDestination(<br \/>\n                  QCameraImageCapture::CaptureToFile);  \/\/\u4fdd\u5b58\u76ee\u6807<br \/>\n   connect(imageCapture, SIGNAL(readyForCaptureChanged(bool)),<br \/>\n         this, SLOT(on_imageReadyForCapture(bool)));<br \/>\n   connect(imageCapture,SIGNAL(imageCaptured(int, const QImage &amp;)),<br \/>\n         this,SLOT(on_imageCaptured(int, const QImage &amp;)));<br \/>\n   connect(imageCapture,SIGNAL(imageSaved(int, const QString &amp;)),<br \/>\n         this,SLOT(on_imageSaved(int, const QString &amp;)));<br \/>\n}<\/p>\n<p>\u521b\u5efaQCameraImageCapture\u5bf9\u8c61imageCapture\u65f6\u4f20\u9012QCamera\u5bf9\u8c61curCamera\u4f5c\u4e3a\u8f93\u5165\u53c2\u6570&#xff0c;\u5efa\u7acb\u4e0e\u6444\u50cf\u5934\u8bbe\u5907\u7684\u5173\u8054\u3002<\/p>\n<p>setBufferFormat(QVideoFrame::Format_Jpeg)\u8bbe\u7f6e\u7f13\u51b2\u533a\u91cc\u56fe\u7247\u4e3aJPG\u683c\u5f0f\u3002<\/p>\n<p>setCaptureDestination(QCameraImageCapture::CaptureToFile)\u8bbe\u7f6e\u6293\u56fe\u5b58\u50a8\u76ee\u6807\u4e3a\u6587\u4ef6&#xff0c;\u6293\u53d6\u7684\u56fe\u7247\u6587\u4ef6\u4f1a\u81ea\u52a8\u4fdd\u5b58\u5230\u7528\u6237\u76ee\u5f55\u7684\u201c\u56fe\u7247\u201d\u6587\u4ef6\u5939\u91cc\u3002<\/p>\n<p>\u4e3aimageCapture\u76843\u4e2a\u4fe1\u53f7\u5173\u8054\u4e86\u81ea\u5b9a\u4e49\u69fd\u51fd\u6570&#xff0c;\u8fd93\u4e2a\u69fd\u51fd\u6570\u7684\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_imageReadyForCapture(bool ready)<br \/>\n{ \/\/\u53ef\u4ee5\u6293\u56fe\u4e86<br \/>\n  ui-&gt;actCapture-&gt;setEnabled(ready);<br \/>\n}<br \/>\nvoid MainWindow::on_imageCaptured(int id, const QImage &amp;preview)<br \/>\n{ \/\/\u6293\u53d6\u56fe\u7247\u540e\u663e\u793a<br \/>\n   Q_UNUSED(id);<br \/>\n   QImage scaledImage &#061; preview.scaled(ui-&gt;LabCapturedImage-&gt;size(),<br \/>\n               Qt::KeepAspectRatio,  Qt::SmoothTransformation);<br \/>\n   ui-&gt;LabCapturedImage-&gt;setPixmap(QPixmap::fromImage(scaledImage));<br \/>\n}<br \/>\nvoid MainWindow::on_imageSaved(int id, const QString &amp;fileName)<br \/>\n{ \/\/\u6587\u4ef6\u4fdd\u5b58\u540e\u663e\u793a\u4fdd\u5b58\u7684\u6587\u4ef6\u540d<br \/>\n   Q_UNUSED(id);<br \/>\n   LabInfo-&gt;setText(&#034;\u56fe\u7247\u4fdd\u5b58\u4e3a&#xff1a; &#034;&#043;fileName);<br \/>\n}<\/p>\n<p>\u5355\u51fb\u7a97\u53e3\u5de5\u5177\u680f\u4e0a\u7684\u201c\u6293\u56fe\u201d\u6309\u94ae\u53ef\u5b9e\u73b0\u6293\u53d6\u9759\u6001\u56fe\u7247\u529f\u80fd&#xff0c;\u5176\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_actCapture_triggered()<br \/>\n{\/\/\u6293\u56fe \u6309\u94ae<br \/>\n   if (curCamera-&gt;captureMode()!&#061;QCamera::CaptureStillImage)<br \/>\n      curCamera-&gt;setCaptureMode(QCamera::CaptureStillImage);<br \/>\n   imageCapture-&gt;capture();<br \/>\n}<\/p>\n<p>\u8fd9\u91cc\u9996\u5148\u5c06curCamera\u7684\u6293\u53d6\u6a21\u5f0f\u8bbe\u7f6e\u4e3aQCamera::CaptureStillImage&#xff0c;\u7136\u540e\u4f7f\u7528QCameraImage Capture::capture()\u51fd\u6570\u6293\u56fe\u3002<\/p>\n<h4>15.5.5\u3000QMediaRecorder\u89c6\u9891\u5f55\u5236<\/h4>\n<p>QMediaRecorder\u7c7b\u5bf9\u8c61mediaRecorder\u7528\u4e8e\u901a\u8fc7\u6444\u50cf\u5934\u8fdb\u884c\u89c6\u9891\u5f55\u5236&#xff0c;iniVideoRecorder()\u51fd\u6570\u521b\u5efamediaRecorder\u5e76\u8fdb\u884c\u521d\u59cb\u5316\u8bbe\u7f6e&#xff0c;MainWindow\u6784\u9020\u51fd\u6570\u8c03\u7528\u6b64\u51fd\u6570\u3002iniVideoRecorder()\u51fd\u6570\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::iniVideoRecorder()<br \/>\n{\/\/\u521b\u5efaQMediaRecorder\u5bf9\u8c61<br \/>\n   mediaRecorder &#061; new QMediaRecorder(curCamera,this);<br \/>\n   ui-&gt;chkMute-&gt;setChecked(mediaRecorder-&gt;isMuted());<br \/>\n   connect(mediaRecorder, SIGNAL(stateChanged(QMediaRecorder::State)),<br \/>\n         this, SLOT(on_videoStateChanged(QMediaRecorder::State)));<br \/>\n   connect(mediaRecorder, SIGNAL(durationChanged(qint64)),<br \/>\n         this, SLOT(on_videoDurationChanged(qint64)));<br \/>\n}<\/p>\n<p>mediaRecorder\u521b\u5efa\u65f6\u4f20\u9012QCamera\u5bf9\u8c61curCamera\u4f5c\u4e3a\u8f93\u5165\u53c2\u6570\u3002<\/p>\n<p>\u4e3amediaRecorder\u7684\u4e24\u4e2a\u4fe1\u53f7\u8bbe\u7f6e\u4e86\u5173\u8054\u69fd\u51fd\u6570&#xff0c;\u4e24\u4e2a\u69fd\u51fd\u6570\u7684\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_video_stateChanged(QMediaRecorder::State state)<br \/>\n{\/\/\u72b6\u6001\u53d8\u5316<br \/>\n   ui-&gt;actVideoRecord-&gt;setEnabled(state!&#061;QMediaRecorder::RecordingState);<br \/>\n   ui-&gt;actVideoStop-&gt;setEnabled(state&#061;&#061;QMediaRecorder::RecordingState);<br \/>\n}<br \/>\nvoid MainWindow::on_video_durationChanged(qint64 duration)<br \/>\n{<br \/>\n   ui-&gt;LabDuration-&gt;setText(QString(&#034;\u5f55\u5236\u65f6\u95f4:%1 \u79d2&#034;).arg(duration\/1000));<br \/>\n}<\/p>\n<p>on_videoStateChanged()\u51fd\u6570\u4f1a\u6839\u636e\u5f53\u524d\u72b6\u6001\u63a7\u5236\u754c\u9762\u6309\u94ae\u7684\u4f7f\u80fd\u72b6\u6001&#xff0c;on_videoDuration Changed()\u51fd\u6570\u7528\u4e8e\u5f55\u5236\u89c6\u9891\u65f6\u663e\u793a\u5df2\u5f55\u5236\u7684\u6301\u7eed\u65f6\u95f4\u3002<\/p>\n<p>\u5f00\u59cb\u5f55\u50cf\u4e4b\u524d&#xff0c;\u9700\u8981\u5355\u51fb\u201c\u89c6\u9891\u4fdd\u5b58\u6587\u4ef6\u201d\u6309\u94ae\u8bbe\u7f6e\u4e00\u4e2a\u89c6\u9891\u5f55\u5236\u4fdd\u5b58\u7684\u6587\u4ef6\u3002\u201c\u5f00\u59cb\u5f55\u50cf\u201d\u548c\u201c\u505c\u6b62\u5f55\u50cf\u201d\u4e24\u4e2a\u6309\u94ae\u7684\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>void MainWindow::on_actVideoRecord_triggered()<br \/>\n{\/\/\u5f00\u59cb\u5f55\u50cf<br \/>\n   if (!mediaRecorder-&gt;isAvailable())<br \/>\n   {<br \/>\n      QMessageBox::critical(this,&#034;\u9519\u8bef&#034;,<br \/>\n            &#034;\u4e0d\u652f\u6301\u89c6\u9891\u5f55\u5236&#xff01;\\\\n mediaRecorder-&gt;isAvailable()&#061;&#061;false&#034;);<br \/>\n      return;<br \/>\n   }<br \/>\n   if (curCamera-&gt;captureMode()!&#061;QCamera::CaptureVideo)<br \/>\n      curCamera-&gt;setCaptureMode(QCamera::CaptureVideo);<\/p>\n<p>   QString selectedFile&#061;ui-&gt;editOutputFile-&gt;text().trimmed();<br \/>\n   if (selectedFile.isEmpty())<br \/>\n   {   QMessageBox::critical(this,&#034;\u9519\u8bef&#034;,&#034;\u8bf7\u5148\u8bbe\u7f6e\u5f55\u97f3\u8f93\u51fa\u6587\u4ef6&#034;);<br \/>\n      return;<br \/>\n   }<br \/>\n   if (QFile::exists(selectedFile))<br \/>\n    if (!QFile::remove(selectedFile))<br \/>\n    {  QMessageBox::critical(this,&#034;\u9519\u8bef&#034;,&#034;\u6240\u8bbe\u7f6e\u5f55\u97f3\u8f93\u51fa\u6587\u4ef6\u88ab\u5360\u7528&#xff0c;\u65e0\u6cd5\u5220\u9664&#034;);<br \/>\n      return;<br \/>\n    }<\/p>\n<p>   mediaRecorder-&gt;setOutputLocation(QUrl::fromLocalFile(selectedFile));<br \/>\n   mediaRecorder-&gt;record();<br \/>\n}<br \/>\nvoid MainWindow::on_actVideoStop_triggered()<br \/>\n{\/\/\u505c\u6b62\u5f55\u50cf<br \/>\n   mediaRecorder-&gt;stop();<br \/>\n}<\/p>\n<p>\u5f00\u59cb\u5f55\u50cf\u4e4b\u524d&#xff0c;\u8fd8\u9700\u8981\u5c06\u6444\u50cf\u5934\u7684\u6293\u53d6\u72b6\u6001\u8bbe\u7f6e\u4e3aQCamera::CaptureVideo&#xff0c;\u7136\u540e\u68c0\u67e5\u8bbe\u7f6e\u7684\u89c6\u9891\u8f93\u51fa\u6587\u4ef6&#xff0c;\u5f53\u6587\u4ef6\u6ca1\u95ee\u9898\u540e\u7528setOutputLocation()\u51fd\u6570\u8bbe\u7f6e\u89c6\u9891\u5f55\u5236\u8f93\u51fa\u6587\u4ef6\u3002<\/p>\n<p>\u8c03\u7528QMediaRecorder\u7684record()\u51fd\u6570\u5f00\u59cb\u5f55\u50cf&#xff0c;stop()\u51fd\u6570\u505c\u6b62\u5f55\u50cf\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7b2c15\u7ae0\u3000\u591a\u5a92\u4f53<br \/>\n\u591a\u5a92\u4f53\u529f\u80fd\u6307\u7684\u4e3b\u8981\u662f\u8ba1\u7b97\u673a\u7684\u97f3\u9891\u548c\u89c6\u9891\u7684\u8f93\u5165\u3001\u8f93\u51fa\u3001\u663e\u793a\u548c\u64ad\u653e\u7b49\u529f\u80fd&#xff0c;Qt\u7684\u591a\u5a92\u4f53\u6a21\u5757\u4e3a\u97f3\u9891\u548c\u89c6\u9891\u64ad\u653e\u3001\u5f55\u97f3\u3001\u6444\u50cf\u5934\u62cd\u7167\u548c\u5f55\u50cf\u7b49\u63d0\u4f9b\u652f\u6301&#xff0c;\u751a\u81f3\u8fd8\u63d0\u4f9b\u6570\u5b57\u6536\u97f3\u673a\u7684\u652f\u6301\u3002\u672c\u7ae0\u5c06\u4ecb\u7ecdQt\u591a\u5a92\u4f53\u6a21\u5757\u7684\u529f\u80fd\u548c\u4f7f\u7528\u3002<br \/>\n15.1\u3000Qt\u591a\u5a92\u4f53\u6a21\u5757\u529f\u80fd\u6982\u8ff0<br \/>\nQt\u591a\u5a92\u4f53\u6a21\u5757\u63d0\u4f9b\u4e86\u5f88\u591a\u7c7b&#xff0c;\u53ef\u4ee5\u5b9e\u73b0\u5982\u4e0b\u7684\u4e00\u4e9b\u529f\u80fd&#xff1a;\u8bbf\u95ee\u539f\u59cb\u97f3\u9891\u8bbe\u5907\u8fdb\u884c\u8f93\u5165\u6216\u8f93\u51fa&#xff1b;\u4f4e\u5ef6\u8fdf\u64ad\u653e\u97f3\u6548\u6587\u4ef6&#xff0c;\u5982WAV\u6587\u4ef6&#xff1b;\u4f7f\u7528\u64ad<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[10580,218,305],"topic":[],"class_list":["post-109023","post","type-post","status-publish","format-standard","hentry","category-server","tag-qt5","tag-qt","tag-305"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010Qt\u3011\u300aQt 5.9 C++\u5f00\u53d1\u6307\u5357\u300b\u7b14\u8bb0-Chapter15-\u591a\u5a92\u4f53 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/109023.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010Qt\u3011\u300aQt 5.9 C++\u5f00\u53d1\u6307\u5357\u300b\u7b14\u8bb0-Chapter15-\u591a\u5a92\u4f53 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u7b2c15\u7ae0\u3000\u591a\u5a92\u4f53 \u591a\u5a92\u4f53\u529f\u80fd\u6307\u7684\u4e3b\u8981\u662f\u8ba1\u7b97\u673a\u7684\u97f3\u9891\u548c\u89c6\u9891\u7684\u8f93\u5165\u3001\u8f93\u51fa\u3001\u663e\u793a\u548c\u64ad\u653e\u7b49\u529f\u80fd&#xff0c;Qt\u7684\u591a\u5a92\u4f53\u6a21\u5757\u4e3a\u97f3\u9891\u548c\u89c6\u9891\u64ad\u653e\u3001\u5f55\u97f3\u3001\u6444\u50cf\u5934\u62cd\u7167\u548c\u5f55\u50cf\u7b49\u63d0\u4f9b\u652f\u6301&#xff0c;\u751a\u81f3\u8fd8\u63d0\u4f9b\u6570\u5b57\u6536\u97f3\u673a\u7684\u652f\u6301\u3002\u672c\u7ae0\u5c06\u4ecb\u7ecdQt\u591a\u5a92\u4f53\u6a21\u5757\u7684\u529f\u80fd\u548c\u4f7f\u7528\u3002 15.1\u3000Qt\u591a\u5a92\u4f53\u6a21\u5757\u529f\u80fd\u6982\u8ff0 Qt\u591a\u5a92\u4f53\u6a21\u5757\u63d0\u4f9b\u4e86\u5f88\u591a\u7c7b&#xff0c;\u53ef\u4ee5\u5b9e\u73b0\u5982\u4e0b\u7684\u4e00\u4e9b\u529f\u80fd&#xff1a;\u8bbf\u95ee\u539f\u59cb\u97f3\u9891\u8bbe\u5907\u8fdb\u884c\u8f93\u5165\u6216\u8f93\u51fa&#xff1b;\u4f4e\u5ef6\u8fdf\u64ad\u653e\u97f3\u6548\u6587\u4ef6&#xff0c;\u5982WAV\u6587\u4ef6&#xff1b;\u4f7f\u7528\u64ad\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/109023.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-22T23:56:54+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"24 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/109023.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/109023.html\",\"name\":\"\u3010Qt\u3011\u300aQt 5.9 C++\u5f00\u53d1\u6307\u5357\u300b\u7b14\u8bb0-Chapter15-\u591a\u5a92\u4f53 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-22T23:56:54+00:00\",\"dateModified\":\"2026-09-22T23:56:54+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/109023.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/109023.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/109023.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010Qt\u3011\u300aQt 5.9 C++\u5f00\u53d1\u6307\u5357\u300b\u7b14\u8bb0-Chapter15-\u591a\u5a92\u4f53\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010Qt\u3011\u300aQt 5.9 C++\u5f00\u53d1\u6307\u5357\u300b\u7b14\u8bb0-Chapter15-\u591a\u5a92\u4f53 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/109023.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010Qt\u3011\u300aQt 5.9 C++\u5f00\u53d1\u6307\u5357\u300b\u7b14\u8bb0-Chapter15-\u591a\u5a92\u4f53 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u7b2c15\u7ae0\u3000\u591a\u5a92\u4f53 \u591a\u5a92\u4f53\u529f\u80fd\u6307\u7684\u4e3b\u8981\u662f\u8ba1\u7b97\u673a\u7684\u97f3\u9891\u548c\u89c6\u9891\u7684\u8f93\u5165\u3001\u8f93\u51fa\u3001\u663e\u793a\u548c\u64ad\u653e\u7b49\u529f\u80fd&#xff0c;Qt\u7684\u591a\u5a92\u4f53\u6a21\u5757\u4e3a\u97f3\u9891\u548c\u89c6\u9891\u64ad\u653e\u3001\u5f55\u97f3\u3001\u6444\u50cf\u5934\u62cd\u7167\u548c\u5f55\u50cf\u7b49\u63d0\u4f9b\u652f\u6301&#xff0c;\u751a\u81f3\u8fd8\u63d0\u4f9b\u6570\u5b57\u6536\u97f3\u673a\u7684\u652f\u6301\u3002\u672c\u7ae0\u5c06\u4ecb\u7ecdQt\u591a\u5a92\u4f53\u6a21\u5757\u7684\u529f\u80fd\u548c\u4f7f\u7528\u3002 15.1\u3000Qt\u591a\u5a92\u4f53\u6a21\u5757\u529f\u80fd\u6982\u8ff0 Qt\u591a\u5a92\u4f53\u6a21\u5757\u63d0\u4f9b\u4e86\u5f88\u591a\u7c7b&#xff0c;\u53ef\u4ee5\u5b9e\u73b0\u5982\u4e0b\u7684\u4e00\u4e9b\u529f\u80fd&#xff1a;\u8bbf\u95ee\u539f\u59cb\u97f3\u9891\u8bbe\u5907\u8fdb\u884c\u8f93\u5165\u6216\u8f93\u51fa&#xff1b;\u4f4e\u5ef6\u8fdf\u64ad\u653e\u97f3\u6548\u6587\u4ef6&#xff0c;\u5982WAV\u6587\u4ef6&#xff1b;\u4f7f\u7528\u64ad","og_url":"https:\/\/www.wsisp.com\/helps\/109023.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-22T23:56:54+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"24 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/109023.html","url":"https:\/\/www.wsisp.com\/helps\/109023.html","name":"\u3010Qt\u3011\u300aQt 5.9 C++\u5f00\u53d1\u6307\u5357\u300b\u7b14\u8bb0-Chapter15-\u591a\u5a92\u4f53 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-22T23:56:54+00:00","dateModified":"2026-09-22T23:56:54+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/109023.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/109023.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/109023.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010Qt\u3011\u300aQt 5.9 C++\u5f00\u53d1\u6307\u5357\u300b\u7b14\u8bb0-Chapter15-\u591a\u5a92\u4f53"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/109023","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=109023"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/109023\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=109023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=109023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=109023"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=109023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}