c++ - QList children - struct or custom classes derived from QObject? -
i'm working on qt application on symbian platform. application has sqlite database , initial data populated txt files.
i'm implementing online update data comes in json format. create generic functions in db update class takes qlist
of classes/structs , updated db them. qlist
populated objects either txt, or json.
i have parsing in place, considering better in terms performance:
- creating c++ structs , passing them (as objects hold simple data) wrapped in
qlist
- creating custom classes derived
qobject
, passing them pointers inqlist
, deletingqdeleteall
- any other way...
that depends on whether classes carrying behaviour or state.
they carry behaviour.
then, polymorphic class in order, yes. whether needs inherit
qobject
question. inheritqobject
only if need services (introspection, signals/slots, event handling). otherwise, don't.as
qdeleteall()
: wouldn't go there. instead of naked pointers, use smart pointers, e.g.qsharedpointer
. keep track of number of references payload, deleting when refcount falls zero.in case, don't use
qlist
, more efficient container suchqvector
.they carry state.
then, "dumb"
struct
may suffice. in case, don't useqlist
container, more efficient,qvector
(don't forget make use ofreserve()
method).
in general, try avoid qlist<t>
types t
sizeof(t)>sizeof(void*)
, non-buildin/non-qt-types, because qlist
performance degraded these.
Comments
Post a Comment