PDA

View Full Version : how to make this into a loop



prophet0
5th December 2011, 22:17
header file


public:
QStringListIterator *iterator;
QTimer *timer;

public slots:
void slide();

private:
QLabel *picture;


cpp file


picture = new QLabel(this);

picture->setGeometry(QRect(781,2,475,360));
picture->show();
QDir dir("/home/dev/ttm/images/");
dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
QStringList files = dir.entryList();
QStringList fileNames;

foreach (QString f, files)
fileNames << (dir.absolutePath() + QDir::separator() + f);

iterator = new QStringListIterator(fileNames);

timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(slide()));
timer->start(6000);

void mediazone::slide()
{

if(iterator->hasNext())
{
picture->clear();
picture->setPixmap(QPixmap(iterator->next()));
picture->show();

}

}


I want to make this loop once it hits the last file in the list how would i go about doing so thanks

Santosh Reddy
6th December 2011, 01:33
I want to make this loop once it hits the last file in the list how would i go about doing so thanks

void mediazone::slide()
{
if(iterator->hasNext())
{
picture->clear();
picture->setPixmap(QPixmap(iterator->next()));
picture->show();
}
else
{
iterator->toFront();
}
}

prophet0
7th December 2011, 18:14
i forgot about the else :)

thanks that works perfect :)