我有以下main.qml文件:
import QtQuick 2.5
import QtQuick.Controls 1.4
Item
{
anchors.centerIn: parent
Label
{
id: textLabel
anchors.fill: parent
x: 200
y: 400
}
CustomObject
{
id: customObjectId
}
}
CustomObject是QML在外部二进制资源中定义的文件,由以下rcc命令生成:
rcc -binary -o redTheme.qrc redTheme.rcc
自定义对象.qml
import QtQuick 2.5
import QtQuick.Controls 1.4
Item
{
Rectangle
{
width: 200
height: 120
color: "blue"
Label
{
text: "customObject"
}
}
}
在C++侧面,我像这样注册我的资源:
QResource::registerResource(QCoreApplication::applicationDirPath() + "/data/themes/redTheme.rcc");
函数返回true,表示文件已打开。
然而,在我的main.qml文件CustomObject中不存在。为什么?
CustomObject is not a type
编辑:我已经包装CustomObject成 aQML Module然后将其编译成一个.rcc文件(这意味着该qmldir文件在.qrc. 没有任何区别CustomObject,即使我添加了一个import语句(import redTheme 1.0),仍然不能被识别为一种类型。我的qmldir文件的内容:
module redTheme
CustomObject 1.0 CustomObject.qml