Results 1 to 2 of 2

Thread: QDate.addYears() problem.

  1. #1
    Join Date
    Oct 2007
    Location
    Warminster, England
    Posts
    31
    Thanks
    17
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Angry QDate.addYears() problem.

    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
    Qt Code:
    1. QDate dd;
    2. dd= startdate ( a QDate variable)
    3. while ( dd < enddate ) {
    4. returnvalue = returnvalue + m_amount;
    5. dd.addYears(1);
    6. qstr.clear();
    7. QTextStream(&qstr) << "Weekday transaction of value " << returnvalue <<
    8. " on " << dd.toString();
    9. DebugMessage(qstr); // echos qstr to a log file
    10. }
    To copy to clipboard, switch view to plain text mode 
    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

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDate.addYears() problem.

    try this
    Qt Code:
    1. ...
    2. dd = dd.addYears(1);
    3. ...
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    Carlton (26th February 2009)

Similar Threads

  1. deployment problem: msvc++ 2008 Express, Qt 4.4.3
    By vonCZ in forum Qt Programming
    Replies: 7
    Last Post: 10th November 2008, 15:38
  2. Problem in using QHttp with QTimer
    By Ferdous in forum Newbie
    Replies: 2
    Last Post: 6th September 2008, 13:48
  3. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 10:12
  4. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 09:47
  5. Replies: 16
    Last Post: 7th March 2006, 16:57

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.