Results 1 to 8 of 8

Thread: Inherit from QObject for data-classes?

  1. #1
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Inherit from QObject for data-classes?

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Inherit from QObject for data-classes?

    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.

  3. #3
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Inherit from QObject for data-classes?

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Inherit from QObject for data-classes?

    Oh ok, I got your point...I don't know then
    The best you could do is try

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Inherit from QObject for data-classes?

    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

  6. #6
    Join Date
    Jan 2006
    Posts
    105
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Inherit from QObject for data-classes?

    i want to emit a signal when data has changed. (to the "datacenter")

    looks like i have to try it

    thanks,
    niko

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Inherit from QObject for data-classes?

    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

  8. #8
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Inherit from QObject for data-classes?

    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.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

Similar Threads

  1. SIGNALS in Inherit Classes
    By ^NyAw^ in forum Qt Programming
    Replies: 2
    Last Post: 27th November 2006, 16:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.