PDA

View Full Version : Inherit from QObject for data-classes?



niko
12th July 2007, 20:42
Hello,

In my Application I have a data structure with quite a few objects. A Model-Class that contains (several hundred or more) individual objects.

Currenly the model has a QList containing all sub-objects.

Now I would like to call a function in the model when the sub-object changes. Usually this would be very easy with a signal emitted by the sub-object.
But for this i have to inherit every sub-object from QObject and establish the slot-connection.
Now my question: might i get a performance problem there?

thanks,
niko

guilugi
13th July 2007, 08:13
Well, I do have a class in my application, which I named DataCenter, and it inherits from QObject too.

This class' methods are oftenly called, and I haven't noticed any performance issue yet.

niko
13th July 2007, 15:21
this is what i have currently too. (and makes perfectly sense)

but i have in this "datacenter" many other objects (hundreds) - and wanted to know how this performs...

niko

guilugi
13th July 2007, 15:34
Oh ok, I got your point...I don't know then
The best you could do is try :p

jh
13th July 2007, 22:16
from my experience deleting objects which inherit QObject
is very slow. i developed an application with
some 100.000 objects and it became a problem
there (was Qt3.1). maybe that changed in the new Qt versions.
you have to try it.
usually Qt is very well designed and performs quiet fast.

what is the reason you want to subclass QObject?

regards,
jh

niko
14th July 2007, 06:43
i want to emit a signal when data has changed. (to the "datacenter")

looks like i have to try it :D

thanks,
niko

jh
14th July 2007, 13:56
if you want avoid sublassing QObject you can write a
'messaging'-class which provides a method to
send signals. you only have to create one object of this class
and you can use it for thousands of data-objects.

jh

Michiel
14th July 2007, 15:09
An alternative is to only access the small objects through the datacenter interface.

The performance-cost of using signals/slots depends on how often the small objects change. If this happens only once in a while, it doesn't matter.