Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.7.3
-
None
Description
Import of Qt3D.Core (Although unused) results with warning (QML QtObject: Created graphical object was not placed in the graphics scene) in the following code:
import QtQuick // as soon as this import is added, warnings appear import Qt3D.Core as Unused Window { width: 640 height: 480 visible: true // if 'target' and 'child' are Items no warning appears // if at least one is a QtObject a warning does appear Item { id: target } Component { id: child QtObject {} } Component.onCompleted: { child.createObject(target); } }
The reason for this problem is probably that on loading of Qt3D Core plugin the following code is run:
QQmlPrivate::RegisterAutoParent autoparent = { 0, &qquick3ditem_autoParent }; QQmlPrivate::qmlregister(QQmlPrivate::AutoParentRegistration, &autoparent);
The following fix should fix the problem:
static QQmlPrivate::AutoParentResult qquick3ditem_autoParent(QObject *obj, QObject *parent) { auto parentNode = qmlobject_cast<Qt3DCore::QNode *>(parent); if (parentNode) { auto node = qmlobject_cast<Qt3DCore::QNode *>(obj); if (node) { // A QNode has another QNode child node->setParent(parentNode); return QQmlPrivate::Parented; } // FIX: the following line should be // } else if (qmlobject_cast<Qt3DCore::QNode *>(obj)) { } else { return QQmlPrivate::IncompatibleParent; } return QQmlPrivate::IncompatibleObject; }
Compare qt3d (invalid): https://github.com/qt/qt3d/blob/6.7.3/src/quick3d/quick3d/qt3dquick_global.cpp
and same function for quick3d (ok): https://github.com/qt/qtquick3d/blob/6.7.3/src/quick3d/plugin.cpp