Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Solved Add hours:min from TextField to hours:min from other bigger 24h

    QML and Qt Quick
    1
    2
    388
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      filipdns last edited by A Former User

      Hello,
      I have TextField with hours:minutes format (example 625:45) and the other with 200:30 and I need to obtain 826:15 on the third one, how can I do that?...

      thanks you for your help

      1 Reply Last reply Reply Quote 0
      • F
        filipdns last edited by filipdns

        I found myself how to do lol

        functionadd.js

        function addhours(str1,str2)
        {
        
            var res1 = str1.split(":")
            var hours1 = parseInt(res1[0]);
            var minutes1 = parseInt(res1[1]);
        
            var res2 = str2.split(":")
            var hours2 = parseInt(res2[0]);
            var minutes2 = parseInt(res2[1]);
             var res3 = hours1 + hours2
             var res4 = minutes1 + minutes2
        
              if (res4>= 60)
              {
                  res4 = res4 - 60;
                  res3 = res3 + 1;
              }
              if (res4<=9)
              {
                  res4 = "0"+ res4
              }
        
              var timeres = res3 + ":" + res4;
              return timeres ;
        }
        

        file.qml

        
        import "functionadd.js" as JS1
        
        
        resulthourInput.text = JS1.addhours(hour1Input.text,hour2Input.text);
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post