gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 13:56:48 34 4
gpt4 key购买 nike

我没时间添加功能来工作。我正在使用 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");
}

最佳答案

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

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

请注意,成员函数在文档中为“const”。

关于qt - 在 Qt 中向 QTime 和 QDateTime 添加时间的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3783979/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com