[英]ReferenceError delegate is not defined. Why?
I have a Qt Creator project with the following directory layout: 我有一个具有以下目录布局的Qt Creator项目:
Now, in file main.qml
I am trying to include UePeopleItemDelegate.qml
: 现在,在文件main.qml
我试图包含UePeopleItemDelegate.qml
:
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2
import QtMultimedia 5.0
import QtQuick.Layouts 1.0
import QtTest 1.1
import "gui/delegates"
ApplicationWindow {
id: ueWindowMain
title: qsTr("TestClient ver 1.00")
width: Screen.desktopAvailableWidth
height: Screen.desktopAvailableWidth
visible: true
opacity: 1.0
contentOrientation: Qt.LandscapeOrientation
color: "black"
ListView {
id: uePeopleListView
snapMode: ListView.SnapToItem
highlightRangeMode: ListView.ApplyRange
anchors.right: parent.right
anchors.rightMargin: 0
anchors.bottom: parent.top
anchors.bottomMargin: -128
anchors.left: parent.left
anchors.leftMargin: 0
anchors.top: parent.top
anchors.topMargin: 0
orientation: ListView.Horizontal
flickableDirection: Flickable.HorizontalFlick
antialiasing: true
delegate: UePeopleItemDelegate
model: ListModel {
ListElement {
name: "Grey"
colorCode: "grey"
}
ListElement {
name: "Red"
colorCode: "red"
}
ListElement {
name: "Blue"
colorCode: "blue"
}
ListElement {
name: "Green"
colorCode: "green"
}
}
}
}
The project compiles and builds without problem, however, I get the following runtime error, which is related to QML: 该项目的编译和生成没有问题,但是,我收到以下与QML相关的运行时错误:
qrc:/main.qml:43: ReferenceError: UePeopleItemDelegate is not defined. qrc:/main.qml:43:ReferenceError:未定义UePeopleItemDelegate。
The error refers to line 错误是指行
delegate: UePeopleItemDelegate
of main.qml
. 的main.qml
。 Why UePeopleItemDelegate
is not recognized? 为什么不能识别UePeopleItemDelegate
? I've imported it with import "gui/delegates"
statement. 我已经使用import "gui/delegates"
语句import "gui/delegates"
其import "gui/delegates"
。 What am I missing? 我想念什么?
Maybe the problem is you are not using braces. 也许问题是您没有使用牙套。 Try this: 尝试这个:
delegate: UePeopleItemDelegate {}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.