Qt 示例:com.qmlqb.qmlcomponents 未安装

Qt Example: com.qmlqb.qmlcomponents is not installed

我正在研究书中的一个示例,"Getting Started with Qt Quick",示例代码有一个 MainForm.ui.qml,其中包含以下导入:

import com.qmlqb.qmlcomponents 1.0

当我尝试 运行 时,我收到此错误:

qrc:/MainForm.ui.qml:4 module "com.qmlqb.qmlcomponents" is not installed

这个导入是什么?如何安装?

所以我知道发生了什么事。我试图在 Qt 中访问 C++ class,它在 main.cpp 中使用以下语句注册:

qmlRegisterType ("Com.qmlqb.qmlcomponents",1,0,"MyClass");

documentation on qmlRegisterType 指定第一个参数是将导入类型的库的名称。

因此,我随后尝试使用以下导入语句在 MainForm.ui.qml 中导入该库,这引发了错误:

import com.qmlqb.qmlcomponents 1.0

如您所见,两者的大小写不同。修复后,一切都很好:)