4

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

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

这是我正在使用的代码:

QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
qmlRegisterType<Execom>("Komut",1,0,"Execom");
4

1 回答 1

8

Instead of this:

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

Do this:

qmlRegisterType<Execom>("Komut",1,0,"Execom");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
于 2015-02-06T17:20:59.817 回答