Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting QObject children

i noticed that QObject::children() method return a const reference to QObjectList, that contains the children of the qobject. Will it be safe to cast away the constness and sort the list with qSort?

Thanks Anton

like image 444
ak. Avatar asked Mar 17 '26 10:03

ak.


1 Answers

No, you should not do this. This is the definition of QObject::children():

inline const QObjectList &children() const { return d_ptr->children; }

This means you directly get the reference of the internal objectlist. And the documentation says:

Note that the list order changes when QWidget children are raised or lowered. A widget that is raised becomes the last object in the list, and a widget that is lowered becomes the first object in the list.

It looks like a bad idea to mess with this list.

like image 173
hmuelner Avatar answered Mar 19 '26 21:03

hmuelner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!