我正在使用 Qt 5.2 和 QtQuick 2.2。在我的项目中,我有几个模块放置在单独的目录中。我的问题是在定义属性时我不能在 typename 中使用点分隔符。例如:
MyRect.qml
import QtQuick 2.2
Rectangle {
id: root
property color rectColor: "white"
color: root.rectColor
}
MyRectInRect.qml
import QtQuick 2.2
import "./" as MyModule
Rectangle {
id: root
property MyModule.MyRect innerRect: MyModule.MyRect { }
// ^ error: Unexpected token `.'; Unexpected token `identifier'
}
我已经在手册中搜索了可以解释此行为的内容,但看起来那里没有任何内容。我猜想在属性定义的“类型”字段中不允许使用点符号。但是有什么方法可以明确定义,哪个模块中的哪个组件应该用作类型?因为可能需要声明具有相同类型名但来自不同模块的属性。