Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a simple way of limiting QObject::findChild() to direct children only?

Tags:

qt

qobject

Question is in the title. I can't find anything obvious in the documentation which suggests a way of doing this. Must I use the recursive children finding methods and test each child's parent pointer sequentially to filter out the non-direct children?

Incidentally, the documentation seems to refer to "direct ancestor"s by which I think it means "direct descendant".

(edit: I'm looking for simplicity, so the answer doesn't have to use the findChild() method.)

like image 823
Samuel Harmer Avatar asked Dec 01 '25 09:12

Samuel Harmer


1 Answers

I have added a flag to QObject::findChild() in Qt 5, called Qt::FindDirectChildOnly, which allows you to do exactly this.

So this issue will soon be a problem of the past :-)

like image 199
David Faure Avatar answered Dec 03 '25 06:12

David Faure