PDA

View Full Version : QLabel + timers



prophet0
20th March 2012, 20:40
So im making a picture loop but seem to be a little stuck
in main


sClientz2_300_300Data = _myParse->getClientz2_300_300();

z2_300_300 = new QLabel(this);
z2s1_Iterator = new QStringListIterator(sClientz2_300_300Data);
z2_300_300->setGeometry(QRect(781,34,475,360));
QTimer::singleShot(0,this, SLOT(startZ2S1()));



startZ2S1()


if(z2s1_Iterator->hasNext())
{
z2_300_300->clear();
z2_300_300->setPixmap(QPixmap("/ttm/images/" + z2s1_Iterator->next()));
z2_300_300->show();
}
if(!z2s1_Iterator->hasNext())
{
z2s1_Iterator->toFront();
}
emit doneZ2S1();


the problem i am having is getting this to display the first one only and dont display the next one untill this function is called again

how would i be able to modify my code to do the above?

ChrisW67
20th March 2012, 21:46
Seems obvious enough... don't use a single shot timer if you want more than one shot. It is all in the QTimer details.

prophet0
20th March 2012, 21:50
Thanks so much

prophet0
23rd March 2012, 16:52
so the fallowing code seems to be missing 1 of the strings in the list

From Debugger:


sClientz2_300_300Data <2 items> QStringList
[0] "fb70a926de17ed214dcbe1edd64c2d96.png" QString
[1] "cd3eb7c9403913bf59b414dff8f64d54.png" QString


so the stringlist sClientz2_300_300Data has 2 items 0,1 but when the following is executed

in main()


z2_300_300 = new QLabel(this);
timerZ2S1 = new QTimer(this);
z2s1_Iterator = new QStringListIterator(sClientz2_300_300Data);
z2_300_300->setGeometry(QRect(781,34,475,360));
connect(timerZ2S1, SIGNAL(timeout()), this, SLOT(startZ2S1()));
timerZ2S1->start(4000);


in startZ2S1()


if(z2s1_Iterator->hasNext())
{
z2_300_300->clear();
//QPixmap *pixmap = new QPixmap("/ttm/images/" + z2s1_Iterator->next());
QString pixpath = "/ttm/images/" + z2s1_Iterator->next();
z2_300_300->setPixmap(QPixmap(pixpath));
}
if(!z2s1_Iterator->hasNext())
{
z2s1_Iterator->toFront();
}


when the above code is executed it skips item 0 and goes to item 1 and loops it every time timeout() is called

where am i going wrong ?

Spitfire
26th March 2012, 16:57
It should work, unless you're doing something wrong somewhere else which you're not showing here.

Create a compilable example of the issue if you can.
I can bet you'll realize your mistake when preparing the example :)