PDA

View Full Version : QDate.addYears() problem.



Carlton
26th February 2009, 01:09
I need to set up a loop that increments a date between a startdate and enddate (both QDate variables). When I increment the loop variable dd using dd.addYears(1), dd does not change, hence the while loop runs for ever.
Why does the code below


QDate dd;
dd= startdate ( a QDate variable)
while ( dd < enddate ) {
returnvalue = returnvalue + m_amount;
dd.addYears(1);
qstr.clear();
QTextStream(&qstr) << "Weekday transaction of value " << returnvalue <<
" on " << dd.toString();
DebugMessage(qstr); // echos qstr to a log file
}

Give the following output for qstr;

Weekday transaction of value 1 on Wed Feb 25 2009
Weekday transaction of value 2 on Wed Feb 25 2009
Weekday transaction of value 3 on Wed Feb 25 2009
Weekday transaction of value 4 on Wed Feb 25 2009
Weekday transaction of value 5 on Wed Feb 25 2009
Weekday transaction of value 6 on Wed Feb 25 2009
Weekday transaction of value 7 on Wed Feb 25 2009
Weekday transaction of value 8 on Wed Feb 25 2009

Have I just done something stupid :confused:

spirit
26th February 2009, 07:22
try this


...
dd = dd.addYears(1);
...