QWidget findChildren shows non existing childs
-
Hi!
I need to catch if child widget is open and I use findChildren from parent.
In first loop, after child widget is initialized in 1 time - I find it with findChildren, and it's ok.
But after closing child widget with close() - the findChildren still shows child object in generated list.
After open child widget in 2 time findChildren shows two copies of child objects.
How findChildren works?
Why findChildren didn't remove a non-existing child objects? -
Hi
That sounds odd.You are 100% sure you clear the list between calls?
Also, close would not normally delete childs unless you are using
Qt::WA_DeleteOnClose.It sounds like you create the child objects on the fly, when you show it.
So maybe you do create them a second time and that is why there are 2 of the same.If you show them many times, you get many in the list or always just 2 ?
-
well if you do
QList<QWidget *> widgetslist = parentWidget.findChildren( ...)then no need to clear it as it is created each time. (and deleted at the end of the function)
I asked just in case you had widgetslist as part of Parent Class.
then doing
widgetslist .clear();
widgetslist = parentWidget.findChildren( ...)
Might been a cure. -
@Buccaneer said:
But after closing child widget with close() - the findChildren still shows child object in generated list.
After open child widget in 2 time findChildren shows two copies of child objects.
How findChildren works?
Why findChildren didn't remove a non-existing child objects?findChildren does not remove anything.
You assumed close() does, but it does not not delete widgets, it only hides them.
So children remain, they are just not visible. -
@mrjj said:
Also, close would not normally delete childs unless you are using
Qt::WA_DeleteOnClose.findChildren does not remove anything.
Thanks to everyone. Qt::WA_DeleteOnClose - that's what I looking for.
I was not familiar with this attribute.
mrjj and alex_malyu you are really helped me.
Thanks