Results 1 to 9 of 9

Thread: How to display time in Progress Bar?

  1. #1
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default How to display time in Progress Bar?

    How to display time in Progress Bar? In which, hours in one progress bar, minutes in one progress bar and seconds in another progress bar, and it should change as the clock?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to display time in Progress Bar?

    Create three progress bars and a custom slot connected to a timer that sets the progress bars according to the current time.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to display time in Progress Bar?

    I have used the following code: but it does nothing.. Please help me in fixing this:

    Qt Code:
    1. #include "dialog.h"
    2. #include "ui_dialog.h"
    3. #include "QDateTime"
    4. #include "QTimer"
    5.  
    6. Dialog::Dialog(QWidget *parent) :
    7. QDialog(parent),
    8. ui(new Ui::Dialog)
    9. {
    10. ui->setupUi(this);
    11.  
    12. ui->m_hours->setValue(0);
    13. ui->m_minutes->setValue(0);
    14. ui->m_seconds->setValue(0);
    15. ui->m_hours->setRange(0,23);
    16. ui->m_minutes->setRange(0,59);
    17. ui->m_seconds->setRange(0,59);
    18.  
    19. QTimer *timer = new QTimer(this);
    20. connect(timer, SIGNAL(timeout()), this, SLOT(prgCtrl()));
    21. timer->start();
    22.  
    23.  
    24. }
    25.  
    26. Dialog::~Dialog()
    27. {
    28. delete ui;
    29. }
    30.  
    31. void Dialog::changeEvent(QEvent *e)
    32. {
    33. QDialog::changeEvent(e);
    34. switch (e->type()) {
    35. case QEvent::LanguageChange:
    36. ui->retranslateUi(this);
    37. break;
    38. default:
    39. break;
    40. }
    41. }
    42.  
    43.  
    44. void Dialog::prgCtrl()
    45. {
    46. dt= QDateTime::currentDateTime();
    47. ui->m_hours->setValue(dt.time().hour());
    48. ui->m_minutes->setValue(dt.time().minute());
    49. ui->m_seconds->setValue(dt.time().second());
    50. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Gokulnathvc; 11th August 2011 at 13:49.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to display time in Progress Bar?

    Why would it do anything if you assign the same values every time?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: How to display time in Progress Bar?

    wysota, this is current time not this same value.
    Gokulnathvc, what is it does nothing ? This code looks good. Show us rest of code, especially how You create an instance of Dialog.

  6. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to display time in Progress Bar?

    Is void Dialog:: prgCtrl(); declared as slot ?
    Qt Code:
    1. void Dialog::prgCtrl()
    2. {
    3. dt= QDateTime::currentDateTime();
    4. qDebug() << "update" << dt;
    5. ui->m_hours->setValue(dt.time().hour());
    6. ui->m_minutes->setValue(dt.time().minute());
    7. ui->m_seconds->setValue(dt.time().second());
    8. }
    To copy to clipboard, switch view to plain text mode 
    Can you see the debug message ?
    Another thing is that you can set one second interval for timer, IMHO there is no need for more frequent ui updates in that case.

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to display time in Progress Bar?

    Quote Originally Posted by Lesiok View Post
    wysota, this is current time not this same value.
    Look at what time wysota has answered and at what time Gokulnathvc has edited his post the last time. This is, by the way, not a very polite way to alter his posts...

  8. #8
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to display time in Progress Bar?

    I have modified my program after Wysota's advice and then i edited here.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to display time in Progress Bar?

    Quote Originally Posted by Gokulnathvc View Post
    I have modified my program after Wysota's advice and then i edited here.
    And then you forgot to mention that it works now. Sometimes I think 6 hours is too long to allow people to edit their posts.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to display progress bar?
    By qutron in forum Newbie
    Replies: 3
    Last Post: 17th May 2011, 16:10
  2. display time as as string ?
    By Petr_Kropotkin in forum Newbie
    Replies: 26
    Last Post: 29th January 2010, 15:46
  3. Display a QWidget on two X-Server at the same time
    By tarod in forum Qt Programming
    Replies: 0
    Last Post: 1st July 2008, 12:55
  4. Show progress of a time consuming operation
    By rainman110 in forum Newbie
    Replies: 7
    Last Post: 10th February 2008, 12:07
  5. Display progress on another thread
    By radu_d in forum Qt Programming
    Replies: 1
    Last Post: 16th October 2007, 08:02

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
  •  
Qt is a trademark of The Qt Company.