Subclassing QColor
-
I would like to extend the QColor class by adding a few class member functions. Can I just subclass QColor? I read the Creating Custom Qt Types. But, that appears to be more for object composition. I want to inherit all the lovely functions already in QColor.
Thanks,
Ryan -
[quote author="rheniser" date="1329264613"]I would like to extend the QColor class by adding a few class member functions. Can I just subclass QColor? I read the Creating Custom Qt Types. But, that appears to be more for object composition. I want to inherit all the lovely functions already in QColor.
Thanks,
Ryan[/quote]
Yes, you can subclass QColor. However, be aware that this class was not designed to be subclassed, as it does not have a virtual destructor. If you start adding members, those might not be properly destructed if you use your subclass as a normal QColor.I don't understand the suggestion for multiple inheritance above. It does not seem to apply, and is generally a practice to avoid for anything but interfaces, IMHO.
-
Qt containers will work as long as your class is copyable and default constructable. If you register your class, then QVariant, Q_PROPERTY and queued signals-slot connections will also work. See the [[doc:QMetaType]] documentation for details on that. If you also need streaming to work for those QVariants, don't forget to implement operator>>() and operator<<() for the type.