Add and Delete in DbTree
Posted: Fri Feb 08, 2019 10:12 am
Hello,
I currently have a problem in my DB Tree.
First of all I create a directory, so I test if it exists or not and I do:
The directory is added to the Db Tree, then I draw different ccCustomHObject and add each new obj in this way:
Once several obj added I want to delete them and continue to add more... and that's when it gets complicated!
I can delete my CustomHObject like that:
Except that an error is triggered on:
With a read access violation....
If I delete my CustomHObject in another way like this:
This does the job and deletes my obj but displays after many assert this error message for each obj deleted!
Would you have a correct method to better manage the addition and deletion of Objects in the dbtree
cheers
I currently have a problem in my DB Tree.
First of all I create a directory, so I test if it exists or not and I do:
Code: Select all
if (!CVisee_group)
{
CVisee_group = new ccHObject(type);
m_app->dbRootObject()->addChild(CVisee_group);
m_app->addToDB(CVisee_group, false, true, false, false);
}
Code: Select all
m_pParentFolderVisee->addChild(pVisee);
m_app->addToDB(pVisee, false, true, false, false);
I can delete my CustomHObject like that:
Code: Select all
ccHObject* root = m_app->dbRootObject();
ccHObject* pChildren = NULL;
for (int i =0; i < root->getChildrenNumber(); i++)
{
pChildren = root->getChild(i);
if (pChildren && pChildren->isKindOf(CC_TYPES::HIERARCHY_OBJECT))
{
ccHObject* pChildren2 = NULL;
for (int j = 0;j < pChildren->getChildrenNumber(); j++)
{
pChildren2 = pChildren->getChild(j);
if (ident == (pChildren2->getMetaData("ident").toInt()))
{
m_app->removeFromDB(pChildren2);
}
}
}
}
Code: Select all
int ccHObject::getIndex() const
{
return (m_parent ? m_parent->getChildIndex(this) : -1);
}
If I delete my CustomHObject in another way like this:
Code: Select all
pChildren2->getParent()->removeChild(pChildren2);
Would you have a correct method to better manage the addition and deletion of Objects in the dbtree
cheers