PDA

View Full Version : strange problem creating a 7-segment clock



sax94
27th April 2012, 15:43
hello everybody
I'm creating a simple application that should be a 7 segment clock, everything works ok when I try this codesnippet


QString hour=QString::number(time.currentTime().hour());
QString min=QString::number(time.currentTime().minute());
QString sec=QString::number(time.currentTime().second());
scene->clear();
for(int i=0;i<6;i++)
{
if(i%2==0 && i>0)
this->designPoints(i);//I design the dots so that the clock looks something like this 00:00:00
QString appoggio;
if(i==0 || i ==1)
appoggio=ImpostaAppoggio(i,hour);//sets the value of appoggio
if(i==2 || i==3 )
appoggio=ImpostaAppoggio(i,min);
if(i==4 || i ==5)
appoggio=ImpostaAppoggio(i,sec);
DisegnaNum(appoggio,i);//I design the seven segments

but when I try this


for(int j=0;j<1000;j++)
{
QString hour=QString::number(time.currentTime().hour());
QString min=QString::number(time.currentTime().minute());
QString sec=QString::number(time.currentTime().second());
scene->clear();
for(int i=0;i<6;i++)
{
if(i%2==0 && i>0)
this->designPoints(i);
QString appoggio;
if(i==0 || i ==1)
appoggio=ImpostaAppoggio(i,hour);
if(i==2 || i==3 )
appoggio=ImpostaAppoggio(i,min);
if(i==4 || i ==5)
appoggio=ImpostaAppoggio(i,sec);
DisegnaNum(appoggio,i);
}
}

no errors or warning occur but no window is showing up and I can't figure out what's going wrong! can someone help?
thank's

sedi
28th April 2012, 01:27
I can't really see what you want to achieve with the for loop. You change and change and change the clock again and again - but you don't return from the routine to let the results be displayed.

Actually I think you might want to have this routine be called every second to update your clock and let the computer do its homework for the rest of the second.
This should be possible with the QTimer, read here (http://qt-project.org/doc/qt-4.8/QTimer.html)about it. You need to put the routine into a public slot (defined that way in the header file) in order to connect the timer's signal to it (e.g. in MainWindow).

I'm not sure if I explained this correctly or if I even understood your intention well enough, though.