PDA

View Full Version : How to constantly refresh time on a view



salmanmanekia
23rd June 2008, 12:27
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

QTime time;
QTimer *update;
QFont fontTime;
QGraphicsTextItem *timeItem;
QString timeString;
..
public slots:
void updateTime();



SOURCE FILE


time = QTime::currentTime();
update = new QTimer();
connect(update,SIGNAL(timeout()),this,SLOT(updateT ime()));
update->start(1000);
timeString = time.toString("hh:mm A");
.. ..
timeItem = scene->addText(timeString);
timeItem->setFont(fontTime);
timeItem->setTextWidth(100);
timeItem->setPos(TIME_TEXT_X,TIME_TEXT_Y);
.. ..
void TrainingUI::updateTime()
{
time = QTime::currentTime();
}

spud
23rd June 2008, 12:32
You need to call timeItem->setText(....) in TrainingUI::updateTime().

salmanmanekia
23rd June 2008, 12:37
thanks for the reply...but there doesnt seem to be any function as setText()...:)

spud
23rd June 2008, 12:39
Sorry, that should be QGraphicsTextItem::setPlainText() or QGraphicsTextItem::setHtml().

munna
23rd June 2008, 12:41
I think you need to add the following code inside the slot.



timeString = time.toString("hh:mm A");
...
...
timeItem = scene->addText(timeString);
timeItem->setFont(fontTime);
timeItem->setTextWidth(100);
timeItem->setPos(TIME_TEXT_X,TIME_TEXT_Y);


Looks like the code is outside.

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

salmanmanekia
23rd June 2008, 12:44
Thanks,it worked..i was calling slot for just updating and not showing it on the view...bad mistake from me..:D