tags:

views:

35

answers:

1

I can't get time adding functions to work. I'm using Qt4. Here is the code snippet, which produces two identical times instead of 100s different.

void main()  
{  
  QTextStream out (stdout);
  QTime t = QTime::currentTime();

  out << t.toString("hh:mm:ss") << " -> ";
  t.addSecs(100);
  out << t.toString("hh:mm:ss");
}
+4  A: 

addSecs() returns a new QTime object that has been adjusted. It doesn't affect the 'this' object.

  out << t.toString("hh:mm:ss") << " -> ";
  QTime t2 = t.addSecs(100);
  out << t2.toString("hh:mm:ss");

Note that the member function is 'const' in the docs.

jkerian
Of course! Thank you! Yet another RTFM carefully case.
Paul Jurczak