我打算给QML文件加载到QGraphicsScene
使用此代码:
QGraphicsScene* scene = new QGraphicsScene;
QQmlEngine *engine = new QQmlEngine;
QQmlComponent component(engine,"main.qml",QQmlComponent::PreferSynchronous);
qDebug()<<component.errors();
QGraphicsObject *object =
qobject_cast<QGraphicsObject *>(component.create());
scene->addItem(object);
错误()返回任何内容和应用程序输出说:
QGraphicsScene::addItem: cannot add null item