songhuirong1 |
2019-12-06 08:13 |
QML Camera问题
写了一个小demo,功能是实现Camera的自动截图。程序能正常运行,但是发现Image无法显示中文路径的图片。望高手指点。 代码如下:
- import QtQuick 2.9
import QtQuick.Window 2.2 import QtMultimedia 5.8
Window { visible: true width: 640 height: 480 title: qsTr("Camera") property int btnHeight: 50
Camera { id: camera }
VideoOutput { anchors.fill: parent source: camera }
Column { anchors.top: parent.top anchors.right: parent.right anchors.bottom: parent.bottom anchors.bottomMargin: listView.height anchors.margins: 10 width: 120 spacing: 9
Rectangle { id: takePhotoRect width: parent.width height: btnHeight color: "darkgray" border.width: 2 border.color: "white"
Text { anchors.centerIn: parent text: qsTr("Take Photo") font.bold: true }
MouseArea { anchors.fill: parent
onClicked: { camera.imageCapture.capture() } } }
Rectangle { id: playSequence width: parent.width height: btnHeight color: "darkgray" border.width: 2 border.color: "white"
Text { anchors.centerIn: parent text: qsTr("Play Sequence") font.bold: true }
MouseArea { anchors.fill: parent
onClicked: {
} } }
Rectangle { id: clearSequence width: parent.width height: btnHeight color: "darkgray" border.width: 2 border.color: "white"
Text { anchors.centerIn: parent text: qsTr("Clear Sequence") font.bold: true }
MouseArea { anchors.fill: parent
onClicked: {
} } } }
ListView { id: listView anchors.left: parent.left anchors.right: parent.right anchors.bottom: parent.bottom width: parent.width height: 50 orientation: ListView.Horizontal model: imgPathsModel delegate: Image { width: 50 height: 50 source: imgPath } }
ListModel { id: imgPathsModel }
Connections { target: camera.imageCapture
onImageSaved: { console.log("path:", path) imgPathsModel.append({"imgPath": path}) } } }
点击“Take Photo”按钮后,本地文件生成相应的图片文件,但是ListView里的Image显示报错。如下: 08:14:53: Starting E:\Qt_Project\build-Camera-Desktop_Qt_5_9_8_MinGW_32bit-Debug\debug\Camera.exe... QML debugging is enabled. Only use this in a safe environment. qml: path: C:/Users/宋慧荣/Pictures/IMG_00000019.jpg qrc:/main.qml:109:19: QML Image: ????Ac????????? 08:16:20: E:/Qt_Project/build-Camera-Desktop_Qt_5_9_8_MinGW_32bit-Debug/debug/Camera.exe exited with code 0
|
|