在Qt中向QTime和QDateTime添加时间的问题

发布于 2024-09-24 20:59:14 字数 282 浏览 0 评论 0原文

我没有时间添加功能来工作。我用的是Qt4。这是代码片段,它产生两个相同的时间,而不是相差 100 秒。

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

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

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");
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寂寞美少年 2024-10-01 20:59:14

addSecs() 返回一个已调整的新 QTime 对象。它不会影响“this”对象。

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

请注意,文档中的成员函数是“const”。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文