Results 1 to 9 of 9

Thread: [Qt] slot of QTimeEdit [problem resolved]

  1. #1
    Join Date
    Jul 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up [Qt] slot of QTimeEdit [problem resolved]

    Hi everyone
    I need to connect a QPushButton with QTimeEdit , for create a chronometer, I'm lost in the doc...
    Thank you
    Last edited by scorpiondezer; 1st July 2008 at 17:20.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: [Qt] slot of QTimeEdit

    What do you want QTimeEdit to do when the button is clicked?
    J-P Nurmi

  3. #3
    Join Date
    Jul 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [Qt] slot of QTimeEdit

    The time run like a chrono

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: [Qt] slot of QTimeEdit

    See documentation of QTimer. Here's an example:
    Qt Code:
    1. QTimer *timer = new QTimer(this);
    2. timer->setInterval(1000);
    3. connect(timer, SIGNAL(timeout()), this, SLOT(updateTime()));
    4. connect(button, SIGNAL(clicked()), timer, SLOT(start()));
    5.  
    6. void MyWindow::updateTime()
    7. {
    8. timeEdit->setTime(QTime::currentTime());
    9. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. #5
    Join Date
    Jul 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [Qt] slot of QTimeEdit

    Thank you your code is perfect, but you use a current time, can I begin by the initialize time in QTimeEdit

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: [Qt] slot of QTimeEdit

    Of course, refer to QTimeEdit and QTime documentations how to get/set the current time of QTimeEdit and how to add time to an existing QTime object.
    J-P Nurmi

  7. #7
    Join Date
    Jul 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [Qt] slot of QTimeEdit

    Thank you very much.
    The problem resolved
    Qt Code:
    1. void Window::updateTime()
    2.  
    3. {
    4. m_s++;
    5. if (m_s>59)
    6. {
    7. m_s=0;
    8. m_m++;
    9.  
    10. }
    11. if (m_m>59)
    12. {
    13. m_m=0;
    14. m_h++;
    15.  
    16. }
    17.  
    18. timeEdit->setTime(QTime(m_h, m_m, m_s));
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: [Qt] slot of QTimeEdit

    Don't you think using QTime::addSecs() would be easier?
    J-P Nurmi

  9. #9
    Join Date
    Jul 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [Qt] slot of QTimeEdit [problem resolved]

    yeees good idea, thank you very much

Similar Threads

  1. How to declare SLOT as a parameter to member function?
    By QPlace in forum Qt Programming
    Replies: 2
    Last Post: 17th July 2018, 00:41
  2. Problem When Creating my own Slot
    By Fatla in forum Qt Programming
    Replies: 12
    Last Post: 6th June 2008, 14:44

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.