Results 1 to 6 of 6

Thread: How to constantly refresh time on a view

  1. #1
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default How to constantly refresh time on a view

    Hi ALL,
    I am developing an application in which i want the clock to show continous time as of my PC(machine) time,when i run the application it shows the time but the time issnt refreshing ,it isnt changing at all ,i have QTimer for that purpose but it doesnt seem to work !!..
    anyhelp would be apprecited..

    HEADER FILE
    Qt Code:
    1. QTime time;
    2. QTimer *update;
    3. QFont fontTime;
    4. QString timeString;
    5. ..
    6. public slots:
    7. void updateTime();
    To copy to clipboard, switch view to plain text mode 

    SOURCE FILE
    Qt Code:
    1. time = QTime::currentTime();
    2. update = new QTimer();
    3. connect(update,SIGNAL(timeout()),this,SLOT(updateTime()));
    4. update->start(1000);
    5. timeString = time.toString("hh:mm A");
    6. .. ..
    7. timeItem = scene->addText(timeString);
    8. timeItem->setFont(fontTime);
    9. timeItem->setTextWidth(100);
    10. timeItem->setPos(TIME_TEXT_X,TIME_TEXT_Y);
    11. .. ..
    12. void TrainingUI::updateTime()
    13. {
    14. time = QTime::currentTime();
    15. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 23rd June 2008 at 12:41. Reason: Changed [qtclass] to [code]

  2. #2
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to constantly refresh time on a view

    You need to call timeItem->setText(....) in TrainingUI::updateTime().

  3. #3
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to constantly refresh time on a view

    thanks for the reply...but there doesnt seem to be any function as setText()...

  4. #4
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to constantly refresh time on a view


  5. #5
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to constantly refresh time on a view

    I think you need to add the following code inside the slot.

    Qt Code:
    1. timeString = time.toString("hh:mm A");
    2. ...
    3. ...
    4. timeItem = scene->addText(timeString);
    5. timeItem->setFont(fontTime);
    6. timeItem->setTextWidth(100);
    7. timeItem->setPos(TIME_TEXT_X,TIME_TEXT_Y);
    To copy to clipboard, switch view to plain text mode 

    Looks like the code is outside.

    [EDIT] Rather, you will need to update the text of your timeItem inside the slot.

  6. #6
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to constantly refresh time on a view

    Thanks,it worked..i was calling slot for just updating and not showing it on the view...bad mistake from me..

Similar Threads

  1. Refresh the Mainwindow at run time
    By sabeesh in forum Qt Programming
    Replies: 3
    Last Post: 15th November 2007, 13:16
  2. Replies: 9
    Last Post: 7th November 2006, 15:10

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.