Qt Quick FolderList实现.svg文件运行时警告/错误

时间:2015-04-17 10:38:12

标签: qt qml qtquick2

在目录/images中,我有几个.svg文件(使用Adobe Illustrator 17和Corel Draw X7创建的矢量图形文件),我想使用{加载到Qt快速应用程序(Qt 5.4.1 for Linux 64bit) {1}}模型将在某些FolderListModel中显示。这是代码:

ListView

当我使用import QtQuick 2.4 import QtQuick.Controls 1.3 import QtQuick.Window 2.2 import QtQuick.Dialogs 1.2 import Qt.labs.folderlistmodel 2.1 ApplicationWindow { id: ueMainWindow visible: true width: 1920 height: 1080 color: "black" title: qsTr("eTestApp") property string ueRootDirectory:"/images" property real ueImagesLoadProgress; property bool ueImageLoading; ListView { id: ueImagesListView width: parent.width height: parent.height FolderListModel { id: ueImageModel folder: "file://"+ueRootDirectory nameFilters: ["*.svg"] } Component { id: ueImageDelegate Image { source: ueImageModel.folder + "/" + fileName } } model: ueImageModel delegate: ueImageDelegate } } 运行包含此代码的项目时,我会在QtCreator目录中找到以下错误的每个.svg文件:

/images

file:///images/filename.svg:1:1: Expected token `numeric literal' file:///images/filename.svg:1:1: Expected a qualified name id 表示filename.svg目录中每个文件的文件名。这是什么意思?

1 个答案:

答案 0 :(得分:0)

AFAIK Loader仅用于加载QML组件,而不是加载svg文件。 http://doc.qt.io/qt-5/qml-qtquick-loader.html#details

如果要加载svg文件,可以使用图像 http://doc.qt.io/qt-5/qml-qtquick-image.html

您可以使用 filePath fileURL 而不是 ueImageModel.folder +“/”+ fileName http://doc.qt.io/qt-5/qml-qt-labs-folderlistmodel-folderlistmodel.html