Results 1 to 6 of 6

Thread: Get typed time from QTimeEdit

  1. #1
    Join Date
    May 2015
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Get typed time from QTimeEdit

    Hi,
    I am developing an adnroid app which can calculate the time in other time zones.
    For displaying the time I am useing the QTimeEdit element.
    Now I want to that the user also can type in a time.
    But I don't get it to work that it get's the typed time.

    I tried it like that:

    Qt Code:
    1. void WeltZeit::on_ENtimeEdit_timeChanged(const QTime &time)
    2. {
    3. QTime enTime = ui->ENtimeEdit->time();
    4. enTime.addSecs(3600); //adds an hour
    5. ui->DEtimeEdit->setTime(enTime);
    6. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Get typed time from QTimeEdit

    Line 3 and 4 should be :
    Qt Code:
    1. QTime enTime = ui->ENtimeEdit->time().addSecs(3600); //adds an hour
    To copy to clipboard, switch view to plain text mode 
    addSecs() does not modify the source object only returns new object.

  3. #3
    Join Date
    May 2015
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Get typed time from QTimeEdit

    Quote Originally Posted by Lesiok View Post
    Line 3 and 4 should be :
    Qt Code:
    1. QTime enTime = ui->ENtimeEdit->time().addSecs(3600); //adds an hour
    To copy to clipboard, switch view to plain text mode 
    addSecs() does not modify the source object only returns new object.
    Thanks it works.


    Added after 1 21 minutes:


    After I did that with all QTimeEdits it doesn't work anymore.


    Qt Code:
    1. void WeltZeit::on_ENtimeEdit_timeChanged(const QTime &time)
    2. {
    3. QTime deTime = ui->ENtimeEdit->time().addSecs(3600); //adds an hour
    4. ui->DEtimeEdit->setTime(deTime);
    5. QTime nyTime = ui->ENtimeEdit->time().addSecs(-18000);
    6. ui->NytimeEdit->setTime(nyTime);
    7. if (DST == 1)
    8. {
    9. QTime jpTime = ui->ENtimeEdit->time().addSecs(28800);
    10. ui->NytimeEdit->setTime(jpTime);
    11. }
    12. else
    13. {
    14. QTime jpTime = ui->ENtimeEdit->time().addSecs(32400);
    15. ui->NytimeEdit->setTime(jpTime);
    16. }
    17.  
    18. }
    19.  
    20.  
    21. void WeltZeit::on_DEtimeEdit_timeChanged(const QTime &time)
    22. {
    23. QTime enTime = ui->DEtimeEdit->time().addSecs(-3600); //adds an hour
    24. ui->ENtimeEdit->setTime(enTime);
    25. QTime nyTime = ui->DEtimeEdit->time().addSecs(-21600);
    26. ui->NytimeEdit->setTime(nyTime);
    27. if (DST == 1)
    28. {
    29. QTime jpTime = ui->DEtimeEdit->time().addSecs(25200);
    30. ui->JPtimeEdit->setTime(jpTime);
    31. }
    32. else
    33. {
    34. QTime jpTime = ui->DEtimeEdit->time().addSecs(28800);
    35. ui->JPtimeEdit->setTime(jpTime);
    36. }
    37. }
    38.  
    39. void WeltZeit::on_JPtimeEdit_timeChanged(const QTime &time)
    40. {
    41. if (DST == 1)
    42. {
    43. QTime enTime = ui->JPtimeEdit->time().addSecs(-28800);
    44. ui->ENtimeEdit->setTime(enTime);
    45. QTime deTime = ui->JPtimeEdit->time().addSecs(-25200);
    46. ui->DEtimeEdit->setTime(deTime);
    47. QTime nyTime = ui->JPtimeEdit->time().addSecs(-46800);
    48. ui->NytimeEdit->setTime(nyTime);
    49. }
    50. else
    51. {
    52. QTime enTime = ui->JPtimeEdit->time().addSecs(-32400);
    53. ui->ENtimeEdit->setTime(enTime);
    54. QTime deTime = ui->JPtimeEdit->time().addSecs(-28800);
    55. ui->DEtimeEdit->setTime(deTime);
    56. QTime nyTime = ui->JPtimeEdit->time().addSecs(-50400);
    57. ui->NytimeEdit->setTime(nyTime);
    58. }
    59. }
    60.  
    61. void WeltZeit::on_NytimeEdit_timeChanged(const QTime &time)
    62. {
    63. QTime enTime = ui->NytimeEdit->time().addSecs(18000); //adds an hour
    64. ui->ENtimeEdit->setTime(enTime);
    65. QTime deTime = ui->NytimeEdit->time().addSecs(21600);
    66. ui->DEtimeEdit->setTime(deTime);
    67. if (DST == 1)
    68. {
    69. QTime jpTime = ui->NytimeEdit->time().addSecs(46800);
    70. ui->JPtimeEdit->setTime(jpTime);
    71. }
    72. else
    73. {
    74. QTime jpTime = ui->NytimeEdit->time().addSecs(50400);
    75. ui->JPtimeEdit->setTime(jpTime);
    76. }
    77. }
    To copy to clipboard, switch view to plain text mode 

    A output of the application is aloso No such signal QTimeEdit::cursorPositionChanged() but I have set the signal on_NytimeEdit_timeChanged().
    Last edited by Reiji; 29th May 2015 at 10:37. Reason: updated contents

  4. #4
    Join Date
    May 2015
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Get typed time from QTimeEdit

    Now I can't type in any other time by keyboard in a QTimeEdit element. It just resets the time to the old time.
    I just recovered an old version of my app. So the problem that I couldn't type a new time by keyboard is vanished. But the problem that it doesn't calculate with the typed time still excists.
    Last edited by Reiji; 29th May 2015 at 13:36.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Get typed time from QTimeEdit

    A output of the application is aloso No such signal QTimeEdit::cursorPositionChanged()
    The warning is perfectly correct but this has nothing to do with the code you have posted. Somewhere in your program you are trying to connect() a QTimeEdit object with an invalid signal name. If you never called connect() directly then you probably have a function on_someTimeEdit_cursorPositionChanged() somewhere in a Qt Designer form class.

    As for the problem "doesn't calculate with the typed time" you will have to explain the problem.
    Where do you see the problem?
    What input do you enter?
    What output do you get?
    Why is the wrong?

  6. #6
    Join Date
    May 2015
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Get typed time from QTimeEdit

    Quote Originally Posted by ChrisW67 View Post
    The warning is perfectly correct but this has nothing to do with the code you have posted. Somewhere in your program you are trying to connect() a QTimeEdit object with an invalid signal name. If you never called connect() directly then you probably have a function on_someTimeEdit_cursorPositionChanged() somewhere in a Qt Designer form class.

    As for the problem "doesn't calculate with the typed time" you will have to explain the problem.
    Where do you see the problem?
    What input do you enter?
    What output do you get?
    Why is the wrong?
    I juste changed the time by keyboard in an QTimeEdit elemet and it automatically calculated the new times for the other QTimeEdit elements and displayed them.
    I realized hat created a slot for every QTimeEdit. for example the for the QTImeElement which displays the Time for the UK:
    Qt Code:
    1. void WeltZeit::on_ENtimeEdit_timeChanged(const QTime &time)
    2. {
    3. QTime deTime = ui->ENtimeEdit->time().addSecs(3600); //adds an hour
    4. ui->DEtimeEdit->setTime(deTime);
    5. QTime nyTime = ui->ENtimeEdit->time().addSecs(-18000);
    6. ui->NytimeEdit->setTime(nyTime);
    7. if (DST == 1)
    8. {
    9. QTime jpTime = ui->ENtimeEdit->time().addSecs(28800);
    10. ui->NytimeEdit->setTime(jpTime);
    11. }
    12. else
    13. {
    14. QTime jpTime = ui->ENtimeEdit->time().addSecs(32400);
    15. ui->NytimeEdit->setTime(jpTime);
    16. }
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 
    But that doesn't work anymore.
    But strangely it works if I change the time via the QTimeEdit for new york(NytimeEdit) and the QTimeEdit for germany(DEtimeEdit).
    Now I only get in QT the output that QTimeEdit::cursorPositionChanged() and nothing happens if I typed the new time.
    I think maybe there is an problem with slots. Maybe(I can't remember) there is still the slot QTimeEdit::cursorPositionChanged() because I used it to try something. For me it changed to that problem just suddenly and since that it never changed and worked again.

    I also set the current time into a QTimeElement of the current Time Zone via the Radio Button.
    for example if I choose the radio Button New York the current time will be displayed in the QTimeElement CTtimeEdit and NyTimeEdit. I do that with the following code:
    Qt Code:
    1. void WeltZeit::on_NewYorkButton_clicked()
    2. {
    3. ui->CTtimeEdit->setTime(ct);
    4. ui->DEtimeEdit->setTime(ct);
    5. ....
    6. }
    To copy to clipboard, switch view to plain text mode 
    The definiation of ct isn't defined in a void so I can acess it in every void(function).
    The definiation of ct is:
    Qt Code:
    1. QTime ct = QTime::currentTime();
    To copy to clipboard, switch view to plain text mode 

    But if I choose the radio button for Japan it's one hour behind and by choosing the button for London even 2 hours behind but I set the current time into the QTimeEdit elemts via the same piece of code(like in the NewYorkButton).
    Last edited by Reiji; 2nd June 2015 at 09:55.

Similar Threads

  1. QTimeEdit : displayformat
    By snakerst in forum Qt Programming
    Replies: 0
    Last Post: 3rd March 2010, 14:11
  2. QTimeEdit maximum time to 24h (24:00:00)
    By doijunior in forum Qt Programming
    Replies: 3
    Last Post: 26th February 2010, 11:50
  3. Qt designer Vs Typed code
    By URPradhan in forum Newbie
    Replies: 1
    Last Post: 22nd January 2010, 11:02
  4. Replies: 1
    Last Post: 15th April 2009, 09:00
  5. QtimeEdit
    By mickey in forum Qt Programming
    Replies: 4
    Last Post: 11th July 2006, 18:04

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.