Results 1 to 3 of 3

Thread: QObject as base class

  1. #1
    Join Date
    Sep 2015
    Posts
    50
    Qt products
    Qt5
    Platforms
    Unix/X11
    Thanks
    8

    Default QObject as base class

    Hello all,

    is it a good idea to create all data objects derived from QObject? Microsoft's MFC Class CObject is built this way but I wanted to see if there is a reason NOT to do this in QT.

    Cheers!
    -Caolan O'Domhnaill

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: QObject as base class

    If you mean value classes, then no.

    You derive from QObject when you need things like properties, signals, slots, components that need to be treated in an abstracted way or communicate with another.

    Or maybe more generically: in C++ you derive from a class if you need to do that, if your new class needs to be treatable as the base class.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Caolan O'Domhnaill (19th October 2015)

  4. #3
    Join Date
    Sep 2015
    Posts
    50
    Qt products
    Qt5
    Platforms
    Unix/X11
    Thanks
    8

    Default Re: QObject as base class

    Quote Originally Posted by anda_skoa View Post
    If you mean value classes, then no.

    You derive from QObject when you need things like properties, signals, slots, components that need to be treated in an abstracted way or communicate with another.

    Or maybe more generically: in C++ you derive from a class if you need to do that, if your new class needs to be treatable as the base class.

    Cheers,
    _
    Aye that's what I was thinking. In MFC, the CObject class allows for serialization of your data which is why you would do it there.

    Thank you!
    -Caolan

Similar Threads

  1. Creating a new c++ class with QObject as a base class
    By toufic.dbouk in forum Qt Programming
    Replies: 11
    Last Post: 1st October 2013, 00:56
  2. Replies: 2
    Last Post: 22nd November 2012, 06:03
  3. Replies: 7
    Last Post: 15th December 2009, 11:01
  4. Replies: 3
    Last Post: 27th December 2008, 20:34
  5. `QObject' is an ambiguous base of `ClientThread'
    By probine in forum Qt Programming
    Replies: 1
    Last Post: 7th December 2006, 14:17

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.