Question

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

Was it helpful?

Solution

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.

OTHER TIPS

Maybe. But why risk it? Can't you just copy the QObjectList and sort your local copy?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top