{"id":55165,"date":"2025-08-13T18:09:31","date_gmt":"2025-08-13T10:09:31","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/55165.html"},"modified":"2025-08-13T18:09:31","modified_gmt":"2025-08-13T10:09:31","slug":"qml%e5%ae%9e%e7%8e%b0%e4%b8%80%e4%b8%aa%e9%9f%b3%e4%b9%90%e6%92%ad%e6%94%be%e5%99%a8%e4%b9%8b-%e6%ad%8c%e8%af%8d%e5%90%8c%e6%ad%a5","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/55165.html","title":{"rendered":"QML\u5b9e\u73b0\u4e00\u4e2a\u97f3\u4e50\u64ad\u653e\u5668\u4e4b---\u6b4c\u8bcd\u540c\u6b65"},"content":{"rendered":"<h2>\u754c\u9762\u6837\u5f0f<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"632\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250813100928-689c6458d006e.gif\" width=\"954\" \/><\/p>\n<h2>\u97f3\u4e50\u64ad\u653e\u5668\u5b9e\u73b0\u6b4c\u8bcd\u540c\u6b65\u7684\u6d41\u7a0b<\/h2>\n<p>1.\u5236\u4f5c\u5f53\u524d\u97f3\u4e50\u7684\u6b4c\u8bcd\u6587\u4ef6&#xff1b;<\/p>\n<p>2.\u901a\u8fc7C&#043;&#043;\u6a21\u5757\u5b9e\u73b0\u5bf9\u5f53\u524d\u6b4c\u66f2\u7684\u6b4c\u8bcd\u6587\u4ef6\u8bfb\u53d6&#xff1b;<\/p>\n<p>3.\u5b9e\u73b0QML\u6b4c\u8bcd\u6587\u4ef6\u7684\u754c\u9762\u5c55\u793a&#xff1b;<\/p>\n<p>4.\u5728\u64ad\u653e\u6b4c\u66f2\u65f6&#xff0c;QML\u6b4c\u8bcd\u754c\u9762\u901a\u8fc7c&#043;&#043;\u5c01\u88c5\u63a5\u53e3\u5b9e\u73b0\u5bf9\u5f53\u524d\u6b4c\u66f2\u4f4d\u7f6e\u7684\u8bfb\u53d6\u5e76\u66f4\u65b0\u6b4c\u8bcd\u663e\u793a\u3002<\/p>\n<\/p>\n<h2>QML\u5b9e\u73b0\u7684\u5173\u952e\u4ee3\u7801<\/h2>\n<p>\u5b9e\u73b0\u6b4c\u8bcd\u7684\u76f8\u5173\u6587\u4ef6\u4e3b\u8981\u7531\u4e09\u4e2a\u6587\u4ef6\u6784\u6210:PlayWindow.qml,LyricsView.qml,LyricsParser.js.<\/p>\n<h3>\u6b4c\u8bcd\u4e3b\u754c\u9762PlayWindow.qml\u4ee3\u7801\u5b9e\u73b0<\/h3>\n<p>import QtQuick 2.1<br \/>\nimport QtQuick.Controls 2.1<br \/>\nimport QtQuick.Window 2.1<br \/>\nimport &#034;LyricsParser.js&#034; as LyricsParser<br \/>\nItem{<\/p>\n<p>    property var name: &#034;\u793a\u4f8b\u6b4c\u66f2&#034;<br \/>\n    property var artist: &#034;\u793a\u4f8b\u6b4c\u624b&#034;<br \/>\n    property var duration: 269<br \/>\n    property var lyrics: &#034;[00:00.00]\u6b4c\u8bcd\u52a0\u8f7d\u4e2d&#8230;&#034;<br \/>\n    property var progress: 0<br \/>\n    function startPlay() {<br \/>\n        if(timer.running){<br \/>\n            return<br \/>\n        }<br \/>\n        btnPlay.clicked()<br \/>\n    }<br \/>\n    function stopPlay() {<br \/>\n        if(!timer.running){<br \/>\n            return<br \/>\n        }<br \/>\n        btnPlay.clicked()<br \/>\n    }<br \/>\n    function updateCurMusic(msg){<br \/>\n        var data &#061; msg<br \/>\n        console.log(&#034;title is :&#034;,String(data[&#034;title&#034;]))<br \/>\n        console.log(&#034;artist is :&#034;,String(data[&#034;artist&#034;]))<br \/>\n        console.log(&#034;duration is :&#034;,String(data[&#034;duration&#034;]))<br \/>\n\/\/        console.log(&#034;lyrics :&#034;,String(data[&#034;lyrics&#034;]));<\/p>\n<p>        name &#061; String(data[&#034;title&#034;])<br \/>\n        artist &#061; String(data[&#034;artist&#034;])<br \/>\n        duration &#061; String(data[&#034;duration&#034;])<br \/>\n        lyrics &#061; String(data[&#034;lyrics&#034;]);<\/p>\n<p>        root.updateMusicInfo()<br \/>\n    }<\/p>\n<p>    function updateProgress(value){<br \/>\n        progress &#061; value<br \/>\n    }<\/p>\n<p>    Rectangle {<br \/>\n        id:root<br \/>\n        anchors.fill: parent<br \/>\n        visible: true<\/p>\n<p>        property var currentSong: {<br \/>\n            &#034;artist&#034;: artist,<br \/>\n            &#034;title&#034;: name,<br \/>\n            &#034;lyrics&#034;: lyrics,<br \/>\n            &#034;duration&#034;: duration<br \/>\n        }<br \/>\n        function updateMusicInfo(){<br \/>\n            musicInfo.formatSongInfo()<br \/>\n            lyricsView.updateLyrics()<br \/>\n            progressBar.totalDuration()<br \/>\n        }<\/p>\n<p>        Rectangle {<br \/>\n            anchors.fill: parent<br \/>\n            gradient: Gradient {<br \/>\n                GradientStop { position: 0; color: &#034;#1e62a0&#034; }<br \/>\n                GradientStop { position: 1; color: &#034;#1e62a0&#034; }<br \/>\n            }<\/p>\n<p>            Column {<br \/>\n                anchors.fill: parent<br \/>\n                spacing: 20<\/p>\n<p>                \/\/ \u6b4c\u66f2\u4fe1\u606f\u533a<br \/>\n                Item {<br \/>\n                    id:musicInfo<br \/>\n                    width: parent.width<br \/>\n                    height: 100<br \/>\n                    \/\/ \u5b9a\u4e49\u683c\u5f0f\u5316\u51fd\u6570<br \/>\n                    function formatSongInfo() {<br \/>\n                        return &#096;${root.currentSong.title} &#8211; ${root.currentSong.artist}&#096;<br \/>\n                    }<br \/>\n                    Text {<br \/>\n                        anchors.centerIn: parent<br \/>\n                        text: musicInfo.formatSongInfo()<br \/>\n                        color: &#034;white&#034;<br \/>\n                        font.pixelSize: 18<br \/>\n                    }<br \/>\n                }<\/p>\n<p>                \/\/ \u6b4c\u8bcd\u663e\u793a\u533a<br \/>\n                LyricsView {<br \/>\n                    id: lyricsView<br \/>\n                    width: parent.width<br \/>\n                    height: parent.height &#8211; 200<\/p>\n<p>                    function updateLyrics(){<br \/>\n                        lyricsView.lyrics &#061; LyricsParser.parseLRC(root.currentSong.lyrics)<br \/>\n                    }<\/p>\n<p>                    lyrics: root.currentSong.lyrics<br \/>\n                }<\/p>\n<p>                \/\/ \u8fdb\u5ea6\u63a7\u5236\u533a<br \/>\n                Slider {<br \/>\n                    id: progressBar<br \/>\n                    width: parent.width &#8211; 40<br \/>\n                    anchors.horizontalCenter: parent.horizontalCenter<br \/>\n                    from: 0<br \/>\n                    to: totalDuration()<br \/>\n                    value: 0<br \/>\n                    visible: false<\/p>\n<p>                    function totalDuration(){<br \/>\n                        console.log(&#034;duration :&#034;,root.currentSong.duration)<br \/>\n                        return root.currentSong.duration<br \/>\n                    }<\/p>\n<p>                    onMoved: {<br \/>\n                        console.log(&#034;progressBar value:&#034;,value*1000)<br \/>\n                        lyricsView.updatePosition(value*1000)<br \/>\n                    }<br \/>\n                }<\/p>\n<p>                \/\/ \u63a7\u5236\u6309\u94ae\u533a<br \/>\n                Row {<br \/>\n                    visible: false<br \/>\n                    anchors.horizontalCenter: parent.horizontalCenter<br \/>\n                    spacing: 30<\/p>\n<p>                    Button {<br \/>\n                        icon.source: &#034;qrc:\/icons\/prev.png&#034;<br \/>\n                        flat: true<br \/>\n                    }<br \/>\n                    Button {<br \/>\n                        id:btnPlay<br \/>\n                        icon.source: &#034;qrc:\/icons\/play.png&#034;<br \/>\n                        flat: true<br \/>\n                        onClicked: {<br \/>\n                            timer.running &#061; !timer.running<br \/>\n                        }<br \/>\n                    }<br \/>\n                    Button {<br \/>\n                        icon.source: &#034;qrc:\/icons\/next.png&#034;<br \/>\n                        flat: true<br \/>\n                    }<br \/>\n                }<\/p>\n<p>            }<br \/>\n        }<\/p>\n<p>        Timer {<br \/>\n            id: timer<br \/>\n            interval: 1000<br \/>\n            running: false<br \/>\n            repeat: true<\/p>\n<p>            function customRound(val) {<br \/>\n                return val &gt; 0 ? Math.floor(val) : Math.ceil(val)<br \/>\n            }<br \/>\n            onTriggered: {<br \/>\n                progressBar.value &#061; progress\/1000.0\/\/\u79d2<br \/>\n                console.log(&#034;value:&#034;,progressBar.value)<br \/>\n                \/\/\u83b7\u53d6\u5f53\u524d\u64ad\u653e\u7684\u8fdb\u5ea6<br \/>\n                lyricsView.updatePosition(progress)\/\/\u6beb\u79d2<br \/>\n                if(progress &gt;&#061; progressBar.to){<br \/>\n                    progressBar.value &#061; 0<br \/>\n                }<br \/>\n            }<br \/>\n        }<\/p>\n<p>    }<br \/>\n}<\/p>\n<h3>\u6b4c\u8bcd\u663e\u793aLyricsView.qml\u4ee3\u7801\u5b9e\u73b0<\/h3>\n<p>import QtQuick 2.1<br \/>\nimport QtQuick.Controls 2.1<br \/>\nItem {<br \/>\n    id: root<br \/>\n    property var lyrics: []<br \/>\n    property int currentIndex: -1<br \/>\n    property alias contentY: flick.contentY<\/p>\n<p>    Flickable {<br \/>\n        id: flick<br \/>\n        anchors.fill: parent<br \/>\n        contentWidth: width<br \/>\n        contentHeight: col.height<br \/>\n        clip: true<\/p>\n<p>        Column {<br \/>\n            id: col<br \/>\n            width: parent.width<br \/>\n            spacing: 15<\/p>\n<p>            Repeater {<br \/>\n                model: root.lyrics<br \/>\n                delegate: Text {<br \/>\n                    width: col.width<br \/>\n                    horizontalAlignment: Text.AlignHCenter<br \/>\n                    text: modelData.text<br \/>\n                    color: index &#061;&#061;&#061; root.currentIndex ? &#034;#1DB954&#034; : &#034;white&#034;<br \/>\n                    font {<br \/>\n                        pixelSize: index &#061;&#061;&#061; root.currentIndex ? 24 : 18<br \/>\n                        bold: index &#061;&#061;&#061; root.currentIndex<br \/>\n                    }<br \/>\n                    opacity: index &#061;&#061;&#061; root.currentIndex ? 1 : 0.7<br \/>\n                    Behavior on color { ColorAnimation { duration: 200 } }<br \/>\n                    Behavior on font.pixelSize { NumberAnimation { duration: 200 } }<br \/>\n                }<br \/>\n            }<br \/>\n        }<br \/>\n    }<br \/>\n    \/\/\u66f4\u65b0\u6b4c\u8bcd\u4f4d\u7f6e<br \/>\n    function updatePosition(time) {<br \/>\n        for (var i &#061; 0; i &lt; lyrics.length; i&#043;&#043;) {<br \/>\n            if (lyrics[i].time &lt;&#061; time &amp;&amp;<br \/>\n                (i &#061;&#061;&#061; lyrics.length &#8211; 1 || lyrics[i&#043;1].time &gt; time)) {<br \/>\n                currentIndex &#061; i<br \/>\n                positionView()<br \/>\n                break<br \/>\n            }<br \/>\n        }<br \/>\n    }<br \/>\n    \/\/\u786e\u4fdd\u5f53\u524d\u64ad\u653e\u6b4c\u8bcd\u663e\u793a\u5230\u4e2d\u95f4\u4f4d\u7f6e<br \/>\n    function positionView() {<br \/>\n        if (currentIndex &lt; 0) return<br \/>\n        var targetY &#061; currentIndex * 45 &#8211; height\/2<br \/>\n        flick.contentY &#061; Math.max(0, Math.min(targetY, flick.contentHeight &#8211; height))<br \/>\n    }<br \/>\n}<\/p>\n<h3>\u6b4c\u8bcd\u89e3\u6790LyricsParser.js\u4ee3\u7801\u5b9e\u73b0<\/h3>\n<p>function parseLRC(text) {<br \/>\n    const lines &#061; text.split(&#039;\\\\n&#039;)<br \/>\n    const result &#061; []<br \/>\n    const timeRegex &#061; \/\\\\[(\\\\d&#043;):(\\\\d&#043;)\\\\.(\\\\d&#043;)\\\\]\/<\/p>\n<p>    lines.forEach(line &#061;&gt; {<br \/>\n        const match &#061; timeRegex.exec(line)<br \/>\n        if (match) {<br \/>\n            const min &#061; parseInt(match[1])<br \/>\n            const sec &#061; parseInt(match[2])<br \/>\n            const ms &#061; parseInt(match[3])<br \/>\n            const time &#061; min * 60000 &#043; sec * 1000 &#043; ms * 10<br \/>\n            const text &#061; line.replace(timeRegex, &#039;&#039;).trim()<br \/>\n            if (text) result.push({ time, text })<br \/>\n        }<br \/>\n    })<\/p>\n<p>    return result.sort((a, b) &#061;&gt; a.time &#8211; b.time)<br \/>\n}<\/p>\n<h3>\u97f3\u4e50\u64ad\u653e\u5668\u4e3b\u754c\u9762\u5173\u952e\u5b9e\u73b0<\/h3>\n<p>import QtQuick 2.1<br \/>\nimport QtQuick.Controls 2.1<br \/>\nimport QtQuick.Layouts 1.1<br \/>\nimport QtQuick.Dialogs 1.3<br \/>\nimport MediaModel 1.0<br \/>\nimport QtQuick.Window 2.1<br \/>\nimport &#034;helper.js&#034; as Helper<\/p>\n<p>ApplicationWindow {<br \/>\n    id: root<br \/>\n    width: 860<br \/>\n    height: 600<br \/>\n    visible: true<br \/>\n    minimumHeight: 600<br \/>\n    minimumWidth: 800<br \/>\n    title: qsTr(&#034;\u97f3\u4e50\u64ad\u653e\u5668&#034;)<\/p>\n<p>    onWidthChanged: console.log(width)<br \/>\n    flags: Qt.FramelessWindowHint<\/p>\n<p>        gradient: Gradient {<br \/>\n            GradientStop { position: 0; color: &#034;#70dfe8&#034; }<br \/>\n            GradientStop { position: 1; color: &#034;#1e62a0&#034; }<br \/>\n        }<br \/>\n    }<\/p>\n<p>     menuBar: AppWindowButtons { }<\/p>\n<p>    property  var lyricsWidget: null<br \/>\n     Item {<br \/>\n         Component.onCompleted: {<br \/>\n             \/\/ \u5c06\u7ec4\u4ef6\u6ce8\u518c\u4e3a\u5168\u5c40\u5c5e\u6027<br \/>\n             Qt._musicPropertyDlg &#061; Qt.createComponent(&#034;SetMetaInfo.qml&#034;)<br \/>\n             if(Qt._musicPropertyDlg.status &#061;&#061;&#061; Component.Ready){<\/p>\n<p>             }else{<br \/>\n                 console.error(&#034;\u7ec4\u4ef6SetMetaInfo.qml\u52a0\u8f7d\u5931\u8d25:&#034;, Qt._musicPropertyDlg.errorString())<br \/>\n             }<\/p>\n<p>         }<br \/>\n         Component.onDestruction: {<br \/>\n             Qt._musicPropertyDlg.destroy()<br \/>\n         }<\/p>\n<p>     }<\/p>\n<p>     property int previousX<br \/>\n     property int previousY<br \/>\n     property point dragPos: Qt.point(0,0)<\/p>\n<p>    ErrorDialog {<br \/>\n        id: errorDialog<br \/>\n    }<br \/>\n    \/\/\u81ea\u5b9a\u4e49C&#043;&#043;\u6a21\u5757<br \/>\n    MediaModel {<br \/>\n        id: dataModel<br \/>\n        onErrorMessage: {<br \/>\n            errorDialog.message &#061; message<br \/>\n            errorDialog.visible &#061; true<br \/>\n        }<br \/>\n    }    <\/p>\n<p>    \/*!<br \/>\n        \\\\brief Left panel<br \/>\n    *\/<br \/>\n    LeftPanel {<br \/>\n        id: leftPanel<br \/>\n        width: 100<br \/>\n        height: parent.height<br \/>\n        anchors.left: parent.left<br \/>\n        topPadding: 20<br \/>\n    }<\/p>\n<p>    \/*!<br \/>\n        \\\\brief Debug draw rect<br \/>\n    *\/<br \/>\n    Rectangle {<br \/>\n        height: parent.height &#8211; 50<br \/>\n        width: parent.width &#8211; leftPanel.width &#8211; 5<br \/>\n        anchors.verticalCenter: parent.verticalCenter<br \/>\n        anchors.right: parent.right<br \/>\n        anchors.rightMargin: 5<br \/>\n        radius: 20<br \/>\n\/\/        color: &#034;#f4f4fe&#034;<br \/>\n        color: &#034;transparent&#034;<br \/>\n        border {<br \/>\n            color: &#034;transparent&#034;<br \/>\n            width: 3<br \/>\n        }        <\/p>\n<p>        ColumnLayout {<br \/>\n            width: parent.width<br \/>\n            height: parent.height<br \/>\n            anchors.fill: parent<\/p>\n<p>            Rectangle {<br \/>\n                id:viewZone<br \/>\n                Layout.fillWidth:  true<br \/>\n                Layout.preferredHeight: parent.height \/ 5*4<br \/>\n                Layout.margins: 2<br \/>\n                visible:  !loader.active<br \/>\n                color: &#034;transparent&#034;<br \/>\n                property bool showTableView: true<\/p>\n<p>                Rectangle{<br \/>\n                    anchors.fill: parent<br \/>\n                    anchors.margins: 2<br \/>\n                    color: &#034;transparent&#034;<br \/>\n                    \/\/\u64ad\u653e\u5217\u8868<br \/>\n                    TableWidget {<br \/>\n                        id: tableView<br \/>\n                        anchors.fill: parent<br \/>\n                        anchors.margins: 2<br \/>\n                        model: dataModel<br \/>\n                        visible: viewZone.showTableView<br \/>\n                    }<\/p>\n<p>                    &#8230;<\/p>\n<p>                    \/\/\u6b4c\u8bcd\u663e\u793a\u754c\u9762<br \/>\n                    PlayerWindow{<br \/>\n                        id: playerWindow<br \/>\n                        anchors.fill: parent<br \/>\n                        anchors.margins: 2<br \/>\n                        visible: !viewZone.showTableView<br \/>\n                        opacity: 1.0<br \/>\n                        onVisibleChanged: {<br \/>\n                            if(visible &#061;&#061;&#061; true){<br \/>\n                                playerWindow.updateCurMusic(dataModel.metaData)<br \/>\n                                playerWindow.startPlay()<br \/>\n                                lyricsTimer.start()<br \/>\n                            }else{<br \/>\n                                playerWindow.stopPlay()<br \/>\n                                lyricsTimer.stop()<br \/>\n                            }<br \/>\n                        }<br \/>\n                        Timer{<br \/>\n                            id:lyricsTimer<br \/>\n                            interval: 1000<br \/>\n                            running: false<br \/>\n                            repeat: true<br \/>\n                            onTriggered: {<br \/>\n                                var value &#061; dataModel.position<br \/>\n                                playerWindow.updateProgress(value)<br \/>\n                            }<br \/>\n                        }<br \/>\n                    }<\/p>\n<p>                    &#8230;<\/p>\n<p>                }<\/p>\n<p>                Button {<br \/>\n                    id:shiftBtn<br \/>\n                    text: &#034;\u5207\u6362\u89c6\u56fe&#034;<br \/>\n                    onClicked: viewZone.showTableView &#061; !viewZone.showTableView<br \/>\n                    visible: false<br \/>\n                }<\/p>\n<p>            }<\/p>\n<p>            Loader {<br \/>\n                id: loader<br \/>\n                Layout.fillWidth: true<br \/>\n                Layout.fillHeight: true<br \/>\n                active: false<br \/>\n            }<\/p>\n<p>            \/*!<br \/>\n                \\\\brief Debug draw rect<br \/>\n            *\/<br \/>\n            Rectangle {<br \/>\n                Layout.fillWidth: true<br \/>\n                Layout.preferredHeight: parent.height \/ 5<br \/>\n                Layout.alignment: Qt.AlignBottom<br \/>\n                color: &#034;plum&#034;<br \/>\n                opacity: 0.8<br \/>\n                visible: !loader.active<\/p>\n<p>                border {<br \/>\n                    color: &#034;transparent&#034;<br \/>\n                    width: 3<br \/>\n                }<\/p>\n<p>                ColumnLayout {<br \/>\n                    width: parent.width<br \/>\n                    height: parent.height<\/p>\n<p>                    \/*!<br \/>\n                        \\\\brief Debug draw rect<br \/>\n                    *\/<br \/>\n                    Rectangle {<br \/>\n                        Layout.alignment: Qt.AlignCenter<br \/>\n                        Layout.preferredWidth: parent.width * 0.75<br \/>\n                        Layout.preferredHeight: 50<br \/>\n                        border {<br \/>\n                            color: &#034;transparent&#034;<br \/>\n                            width: 3<br \/>\n                        }<\/p>\n<p>                        RowLayout {<br \/>\n                            width: parent.width<br \/>\n                            height: parent.height<br \/>\n                            Label {<br \/>\n                                Layout.alignment: Qt.AlignCenter<br \/>\n                                Layout.leftMargin: 5<br \/>\n                                font.pixelSize: 16<br \/>\n                                text: Helper.prependZero(Math.floor(dataModel.position \/ 1000 \/ 60)) &#043; &#034;:&#034;<br \/>\n                                      &#043; Helper.prependZero(Math.floor(dataModel.position \/ 1000 % 60))<br \/>\n                            }<br \/>\n                            CustomSlider {<br \/>\n                                id: seekSlider<br \/>\n                                Layout.preferredWidth: parent.width * 0.75<br \/>\n                                Layout.alignment: Qt.AlignCenter<br \/>\n                            }<br \/>\n                            Label {<br \/>\n                                Layout.alignment: Qt.AlignCenter<br \/>\n                                Layout.rightMargin: 5<br \/>\n                                font.pixelSize: 16<br \/>\n                                text: Helper.prependZero(Math.floor(dataModel.duration \/ 1000 \/ 60)) &#043; &#034;:&#034;<br \/>\n                                      &#043; Helper.prependZero(Math.floor(dataModel.duration \/ 1000 % 60))<br \/>\n                            }<br \/>\n                        }<br \/>\n                    }<br \/>\n                    \/*!<br \/>\n                        \\\\brief Bottom panel<br \/>\n                    *\/<br \/>\n                    ControlPanel {<br \/>\n                        Layout.alignment: Qt.AlignCenter<br \/>\n                        Layout.bottomMargin: 10<br \/>\n                    }<br \/>\n                }<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>}<\/p>\n<h2><\/h2>\n<h2>C&#043;&#043;\u5b9e\u73b0\u7684\u5173\u952e\u4ee3\u7801<\/h2>\n<p>\u5728QML\u6587\u4ef6\u4e2d,\u901a\u8fc7Q_PROPERTY\u5c5e\u6027,\u8bfb\u53d6\u6b4c\u66f2\u7684\u5c5e\u6027\u4fe1\u606f(\u5305\u542b\u6b4c\u8bcd\u4fe1\u606f)<\/p>\n<p>\/*<br \/>\n     * \u83b7\u53d6\u6587\u4ef6\u5c5e\u6027\u4fe1\u606f<br \/>\n     *\/<br \/>\n    Q_PROPERTY(QVariantMap metaData READ metaData WRITE setMetaData )<\/p>\n<p>QVariantMap MediaModel::metaData()<br \/>\n{<br \/>\n    QVariantMap mData;<br \/>\n    QString filePath &#061; m_playlist-&gt;currentMedia().canonicalUrl().toLocalFile();<br \/>\n    TagLib::FileRef f(filePath.toStdString().data());<br \/>\n    if(f.isNull()){<br \/>\n        qDebug() &lt;&lt; &#034;f is null&#034;;<br \/>\n        return mData;<br \/>\n    }<br \/>\n    mData.insert(&#034;artist&#034;, QVariant::fromValue(TStringToQString(f.tag()-&gt;artist())));<br \/>\n    mData.insert(&#034;title&#034;, QVariant::fromValue(TStringToQString(f.tag()-&gt;title())));<br \/>\n    mData.insert(&#034;time&#034;, getMetaData(f).value(&#034;length&#034;));<br \/>\n    mData.insert(&#034;duration&#034;,getMetaData(f).value(&#034;duration&#034;));<br \/>\n    mData.insert(&#034;album&#034;, QVariant::fromValue(TStringToQString(f.tag()-&gt;album())));<\/p>\n<p>    \/\/\u8bbe\u7f6e\u9ed8\u8ba4\u6b4c\u8bcd\u6587\u4ef6<br \/>\n    mData.insert(&#034;lyrics&#034;,QString(&#034;&#034;));<br \/>\n    {<br \/>\n        int pos &#061; filePath.indexOf(&#039;.&#039;);<br \/>\n        QString lyricsFile &#061; filePath.mid(0,pos)&#043;&#034;.lyric&#034;;<br \/>\n        QFile f(lyricsFile);<br \/>\n        QByteArray lyricsContent;<\/p>\n<p>        if(f.exists()&amp;&amp;f.open(QFile::ReadOnly)){<br \/>\n            lyricsContent &#061; f.readAll();<br \/>\n            mData[&#034;lyrics&#034;] &#061; lyricsContent;<br \/>\n            f.close();<br \/>\n        }else{<br \/>\n            qDebug() &lt;&lt; &#034;lyricsFile path:&#034; &lt;&lt; lyricsFile;<br \/>\n        }<br \/>\n    }<\/p>\n<p>\/\/    for(auto elem:mData.keys()){<br \/>\n\/\/        qDebug() &lt;&lt; elem &lt;&lt;&#034; :&#034; &lt;&lt; mData[elem] &lt;&lt; &#034;&#061;&#061;&#034; &lt;&lt; filePath.toStdString().data();<br \/>\n\/\/    }<br \/>\n    return mData;<br \/>\n}<\/p>\n<h2>\u9700\u8981\u6ce8\u610f\u7684\u95ee\u9898<\/h2>\n<p>QML\u6587\u4ef6\u4e2danchors\u4e0eLayout\u4e24\u79cd\u5e03\u5c40\u6bd4\u8f83<\/p>\n<h4>\u4e00\u3001\u5b9a\u4f4d\u673a\u5236\u5dee\u5f02<\/h4>\n<ul>\n<li>\u200c\u951a\u70b9\u7cfb\u7edf\u200c\u901a\u8fc7\u5143\u7d20\u95f4\u7684\u76f8\u5bf9\u5173\u7cfb\u5b9e\u73b0\u7cbe\u786e\u5b9a\u4f4d&#xff08;\u5982anchors.left: parent.right&#xff09;&#xff0c;\u9700\u624b\u52a8\u8ba1\u7b97\u6bd4\u4f8b\u4e14\u4f9d\u8d56\u7236\u5bb9\u5668\u5c3a\u5bf8\u3002<\/li>\n<li>\u200c\u5e03\u5c40\u7cfb\u7edf\u200c&#xff08;\u5982RowLayout\/ColumnLayout&#xff09;\u91c7\u7528\u6d41\u5f0f\u81ea\u52a8\u6392\u5217&#xff0c;\u5185\u7f6e\u6743\u91cd\u5206\u914d\u673a\u5236&#xff08;Layout.fillWidth\u7b49&#xff09;&#xff0c;\u81ea\u52a8\u54cd\u5e94\u5bb9\u5668\u53d8\u5316\u3002<\/li>\n<\/ul>\n<h4>\u4e8c\u3001\u6df7\u5408\u4f7f\u7528\u5efa\u8bae<\/h4>\n<li>\u200c\u4f18\u5148\u5e03\u5c40\u7cfb\u7edf\u200c&#xff1a;\n<ul>\n<li>\u5bf9\u7b49\u95f4\u8ddd\u6392\u5217&#xff08;\u5982\u6309\u94ae\u7ec4&#xff09;\u3001\u8868\u5355\u8f93\u5165\u7b49\u573a\u666f&#xff0c;\u4f7f\u7528RowLayout\/ColumnLayout\u7b80\u5316\u5f00\u53d1\u3002<\/li>\n<li>\u901a\u8fc7Layout.alignment\u63a7\u5236\u5b50\u9879\u5bf9\u9f50&#xff0c;\u907f\u514d\u76f4\u63a5\u7ed1\u5b9ax\/y\u5750\u6807\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u200c\u951a\u70b9\u8865\u5145\u7ec6\u8282\u200c&#xff1a;\n<ul>\n<li>\u5728\u5e03\u5c40\u5bb9\u5668\u5185\u7528\u951a\u70b9\u5fae\u8c03\u5b50\u9879\u4f4d\u7f6e&#xff08;\u5982Text\u5728Rectangle\u4e2d\u5c45\u4e2d&#xff09;\u3002<\/li>\n<li>\u53e0\u52a0\u5c42\u6216\u7edd\u5bf9\u5b9a\u4f4d\u5143\u7d20\u4f7f\u7528anchors.fill\u6216anchors.centerIn\u3002<\/li>\n<\/ul>\n<\/li>\n<h4>\u4e09\u3001\u6ce8\u610f\u4e8b\u9879<\/h4>\n<ul>\n<li>\u200c\u7981\u6b62\u6df7\u7528\u5b9a\u4f4d\u5c5e\u6027\u200c&#xff1a;\u907f\u514d\u540c\u65f6\u8bbe\u7f6eLayout\u548canchors&#xff0c;\u5426\u5219\u5bfc\u81f4\u5e03\u5c40\u51b2\u7a81\u3002<\/li>\n<li>\u200c\u6027\u80fd\u4f18\u5316\u200c&#xff1a;\u951a\u70b9\u7cfb\u7edf\u5728\u7b80\u5355\u573a\u666f\u6027\u80fd\u66f4\u4f18&#xff0c;\u590d\u6742\u5d4c\u5957\u5e03\u5c40\u65f6\u63a8\u8350GridLayout\u7b49\u5bb9\u5668\u3002<\/li>\n<li>\u200c\u54cd\u5e94\u5f0f\u8bbe\u8ba1\u200c&#xff1a;\u5e03\u5c40\u7cfb\u7edf\u5929\u7136\u9002\u914d\u4e0d\u540c\u5c4f\u5e55\u5c3a\u5bf8&#xff0c;\u951a\u70b9\u7cfb\u7edf\u9700\u663e\u5f0f\u7ed1\u5b9awidth\/height\u4fe1\u53f7\u3002<\/li>\n<\/ul>\n<p>\u5173\u952e\u7ed3\u8bba&#xff1a;\u200c\u5e03\u5c40\u7cfb\u7edf\u9002\u5408\u7ed3\u6784\u6027\u754c\u9762&#xff0c;\u951a\u70b9\u7cfb\u7edf\u64c5\u957f\u7cbe\u51c6\u5b9a\u4f4d&#xff1b;\u5b9e\u9645\u5f00\u53d1\u4e2d\u5e38\u7ec4\u5408\u4f7f\u7528&#xff0c;\u4f46\u9700\u907f\u514d\u5c5e\u6027\u51b2\u7a81\u200c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb361\u6b21\uff0c\u70b9\u8d5e11\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u5b66\u4e60QML\u754c\u9762\u5e03\u5c40,\u5b66\u4e60QML\u51fd\u6570\u8c03\u7528<\/p>\n","protected":false},"author":2,"featured_media":55164,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[187,5664,5663],"topic":[],"class_list":["post-55165","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-javascript","tag-qml"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>QML\u5b9e\u73b0\u4e00\u4e2a\u97f3\u4e50\u64ad\u653e\u5668\u4e4b-\u6b4c\u8bcd\u540c\u6b65 - \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\/55165.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"QML\u5b9e\u73b0\u4e00\u4e2a\u97f3\u4e50\u64ad\u653e\u5668\u4e4b-\u6b4c\u8bcd\u540c\u6b65 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb361\u6b21\uff0c\u70b9\u8d5e11\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u5b66\u4e60QML\u754c\u9762\u5e03\u5c40,\u5b66\u4e60QML\u51fd\u6570\u8c03\u7528\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/55165.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-13T10:09:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250813100928-689c6458d006e.gif\" \/>\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=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/55165.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/55165.html\",\"name\":\"QML\u5b9e\u73b0\u4e00\u4e2a\u97f3\u4e50\u64ad\u653e\u5668\u4e4b-\u6b4c\u8bcd\u540c\u6b65 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-13T10:09:31+00:00\",\"dateModified\":\"2025-08-13T10:09:31+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/55165.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/55165.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/55165.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"QML\u5b9e\u73b0\u4e00\u4e2a\u97f3\u4e50\u64ad\u653e\u5668\u4e4b---\u6b4c\u8bcd\u540c\u6b65\"}]},{\"@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":"QML\u5b9e\u73b0\u4e00\u4e2a\u97f3\u4e50\u64ad\u653e\u5668\u4e4b-\u6b4c\u8bcd\u540c\u6b65 - \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\/55165.html","og_locale":"zh_CN","og_type":"article","og_title":"QML\u5b9e\u73b0\u4e00\u4e2a\u97f3\u4e50\u64ad\u653e\u5668\u4e4b-\u6b4c\u8bcd\u540c\u6b65 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb361\u6b21\uff0c\u70b9\u8d5e11\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u5b66\u4e60QML\u754c\u9762\u5e03\u5c40,\u5b66\u4e60QML\u51fd\u6570\u8c03\u7528","og_url":"https:\/\/www.wsisp.com\/helps\/55165.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-13T10:09:31+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/08\/20250813100928-689c6458d006e.gif"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/55165.html","url":"https:\/\/www.wsisp.com\/helps\/55165.html","name":"QML\u5b9e\u73b0\u4e00\u4e2a\u97f3\u4e50\u64ad\u653e\u5668\u4e4b-\u6b4c\u8bcd\u540c\u6b65 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-13T10:09:31+00:00","dateModified":"2025-08-13T10:09:31+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/55165.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/55165.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/55165.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"QML\u5b9e\u73b0\u4e00\u4e2a\u97f3\u4e50\u64ad\u653e\u5668\u4e4b---\u6b4c\u8bcd\u540c\u6b65"}]},{"@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\/55165","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=55165"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/55165\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/55164"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=55165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=55165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=55165"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=55165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}