Closed zhangfq-chemistry closed 2 years ago
Hey,
what do you mean remove them? Do you want to delete them fully or just no display them? In either case, retain a reference/pointer to the object you are creating and store those in a list, e.g.
entitiesList.append(cuboidEntity);
within the loop. Then later, to fully delete them you can do
entitiesList[i].setParent(0)
Setting the parent to 0
on an entity makes the entity delete everything internally. You can then remove this entity from the list.
Sir, I want to remove one or all them via their Index. How to do ?
I tried under ubuntu using qt 5.12, and neither case is correct with errors:
/home/zhangfq/disk1/qt3d-version/0/qt3d/qt3dviewer.h:218: error: call of overloaded ‘setParent(int)’ is ambiguous In file included from ../../../qt3d-version/0/qt3d/qt3dviewer.cpp:1: ../../../qt3d-version/0/qt3d/qt3dviewer.h: In member function ‘void RenderWindow::removeChildren(QVector<Qt3DCore::QEntity*>)’: ../../../qt3d-version/0/qt3d/qt3dviewer.h:218:31: error: call of overloaded ‘setParent(int)’ is ambiguous 218 | child->setParent(0); | ^
void removeChildren(QVector <Qt3DCore::QEntity * > ll)
{
for (auto child : ll)
child->setParent(0); //ambiguous
}
void removeChildren(Qt3DCore::QEntity * entity)
{
auto childenEntity = entity->childNodes();
for (auto child: childenEntity)
child->setParent(0);
}
I'd suggest you ask a question on www.stackoverflow.com, this is not the right place to discuss this. This issue tracker is supposed to be related to the gizmo implementation I created.
I'll still give you some advice:
Your second removeChildren
is uncessary, once you set the parent of an entity to 0
, it automatically deletes all its children, no need to take care of that.
I think you have to replace auto
by the actual type, e.g. Qt3DCore::QEntity*
, since the QNode
(which is the supertype of entity) might have a different setParent
implementation than the entities. That's why it might be ambiuous.
But please refrain from asking further unrelated questions here and go to stackoverflow.
I have several QEntities inside the root, then how to remove one of them? for example:
for(int i=0;i++;i<10) { auto cuboidEntity = new Qt3DCore::QEntity(root); cuboidEntity ->setId(i); }
???