代码之家  ›  专栏  ›  技术社区  ›  Paul Jurczak

qtime和qdatetime在qt中添加时间的问题

  •  2
  • Paul Jurczak  · 技术社区  · 15 年前

    我没时间把函数添加到工作中。我用的是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");
    }
    
    1 回复  |  直到 15 年前
        1
  •  8
  •   jkerian    15 年前

    addsecs()返回已调整的新qtime对象。它不会影响“this”对象。

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

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