Results 1 to 4 of 4

Thread: Making them all QObject's - good or bad practive?

  1. #1
    Join Date
    Oct 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question Making them all QObject's - good or bad practive?

    Hello,

    in a design for a new application I tend to derive all classes from QObject in order to be able to use the Qt framework to the max. I need to mention that I have developed in Java over the past 10 years where everything derives from 'Object'.

    Would somebody consider this a bad practice? I see a lot of benefits: Parent-child, cloning, signals/slots, property support, uniformity, clarity... more?

    What are the disadvantages? Are QObjects too heavy-weight?

    Any thoughts?
    Thanks,
    Andre

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Making them all QObject's - good or bad practive?

    Quote Originally Posted by andre View Post
    What are the disadvantages?
    You can't make a copy of QObject, that's one thing. So for instance you can't have a list of objects derived from QObject, only a list of pointers to objects derived from QObject.

    Qt Code:
    1. QList<QObject> bad;
    2. QList<QObject*> good;
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Making them all QObject's - good or bad practive?

    Quote Originally Posted by wysota View Post
    You can't make a copy of QObject, that's one thing. So for instance you can't have a list of objects derived from QObject, only a list of pointers to objects derived from QObject.
    This would fit my approach very well. I will have a coarse grained object structure and each object will have a unique identity, therefore no urgent need to create massive amounts of copies. If I do create copies, I will do that as part of a separate "business transaction" as copies from a resource like a DB or file. The copies would be completely separated by their context.

    Is there more to consider? Memory footprint? Creation/destruction complexity? Are those things handled well by Qt?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Making them all QObject's - good or bad practive?

    Quote Originally Posted by andre View Post
    Memory footprint? Creation/destruction complexity?
    It depends if we are talking about hundreds or tens of thousands of such objects. If the former, you are safe.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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
  •  
Qt is a trademark of The Qt Company.