qt - Using QObject instead of a container -


after reading on interesting parent-child system of qobject wondering how common qt developers use in place of more traditional container. assuming memory contiguity not requirement, seems offers interesting features.

for example, have qobject , give children of different types, , find children based on types, giving qobject dynamic heterogenous container-like feature, opposed required homogenous collection of traditional container.

and qobject naturally manages memory of children, convenient well.

is common use of feature?

qobject::findchildren slower storing objects in normal container qlist because:

  1. it iterates on children each time. searches recursively (but can disabled).
  2. it performs runtime type check.
  3. it constructs new qlist each time. can slow , expensive there many objects in result.

all above unnecessary if use qlist<type*> my_objects. in case:

  1. you can name collection. qlist<qpushbutton*> panic_buttons clearer findchildren<qpushbutton*>().
  2. you can have several collections of objects of same type.

if want make heterogenous container, can use qhash<any_type_identifier, qobject*>. faster.

maybe, findchildren approach may simplier sometimes. if have many objects or complicated class, you'd better use normal containers. can still use qobject's memory management them without problems.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -