错误:QQmlApplicationEngine 加载组件失败

oks*_*dez 4 c++ qt qml qqmlcomponent qqmlapplicationengine

我尝试注册一个类型,但出现此错误:

QQmlApplicationEngine 加载组件失败
qrc:/main.qml:5 模块“Komut”未安装

这是我正在使用的代码:

QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
qmlRegisterType<Execom>("Komut",1,0,"Execom");
Run Code Online (Sandbox Code Playgroud)

cma*_*t85 8

取而代之的是:

QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
qmlRegisterType<Execom>("Komut",1,0,"Execom");
Run Code Online (Sandbox Code Playgroud)

做这个:

qmlRegisterType<Execom>("Komut",1,0,"Execom");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
Run Code Online (Sandbox Code Playgroud)