一、原因
终极原因:组件没有构建好,有可能是加载的QML路径不对,或者是QML代码错误,或者是QML组件还没有加载完。
二、解决办法
- 打印详细错误
QQmlEngine engine;
QQmlComponent component(&engine, QUrl::fromLocalFile(":/main.qml"));
QObject *obj = component.create();
qDebug() << component.errors();
- 检查QML路径
- 检测组件是否准备好