Skip to content

Instantly share code, notes, and snippets.

@blazovics
Created September 6, 2017 11:08
Show Gist options
  • Save blazovics/d12288867f1bf745612fe710233df219 to your computer and use it in GitHub Desktop.
Save blazovics/d12288867f1bf745612fe710233df219 to your computer and use it in GitHub Desktop.
QObject* findItemByName(QList<QObject*> nodes, const QString& name)
{
for(int i = 0; i < nodes.size(); i++)
{
// Node keresése
if (nodes.at(i) && nodes.at(i)->objectName() == name)
{
return nodes.at(i);
}
// Gyerekekben keresés
else if (nodes.at(i) && nodes.at(i)->children().size() > 0)
{
QObject* item = findItemByName(nodes.at(i)->children(), name);
if (item)
return item;
}
}
return nullptr;
}
QObject* findItemByName(QObject *rootObject, const QString& name)
{
Q_ASSERT(rootObject != nullptr);
if (rootObject->objectName() == name)
{
return (QObject*)rootObject;
}
return findItemByName(rootObject->children(), name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment