PDA

View Full Version : QDate class extension



Carlton
22nd February 2009, 01:13
Is it possible to add new functions to the QDate class :confused:?
In particular, I wanted to add the functions monthsTo(Qdate adate) and yearsTo(QDate adate) to complement the existing daysTo(QDate adate) function.
I know I could create a new class using QDate as a base, ie

class myQDate : public QDate
{
// function prototypes
int QDate::monthsTo(QDate adate);
int QDate::yearsTo(QDate adate);
};
I would then need to change all my QDates to myQDates.
Regarding future projects, is it better practice to create my own classes from the Qt bases if I suspect they may need to be extended.
TIA
Carlton.

wysota
22nd February 2009, 08:33
Instead of extending QDate you may implement standalone functions. Then you won't have to modify any code already written.