[Solved]Runtime Bug in Image Slidshow Application
-
hello everyone
I have created a gui application for slide show of images consisting of a push-button to select a directory from file system and a label to display images at interval of 5 seconds.
It compiles and runs fine if I use it for a single directory but if it is running a slide show and I select another directory then it displays images of both directories.
so anyone can please help me out of this??? -
I think you have forgotten to empty the list of image files before you build
the list from the new directory. But without any code it hard to say for sure. -
I have clear the stringlist before reusing it.
void MainWindow::on_pushButton_clicked()
{
int index=0;
QString DirectryPath,ImagePath;
QStringList SetFilter,FileList;
QDir DirName;FileList.clear(); DirectryPath=QFileDialog::getExistingDirectory(this,tr("Select Folder"),"/home",QFileDialog::ShowDirsOnly|QFileDialog::DontResolveSymlinks); DirectryPath=DirectryPath +'/'; qDebug() << DirectryPath; DirName=DirectryPath; qDebug()<<DirName; SetFilter<<"*.jpg"<<"*.jpeg"<<"*.png"; DirName.setNameFilters(SetFilter); FileList=DirName.entryList(QDir::Files,QDir::NoSort); qDebug() << FileList; qDebug()<<FileList.size(); while(index<FileList.count()) { ImagePath=DirectryPath+FileList[index]; qDebug()<<ImagePath; QImage image(ImagePath); qDebug()<<image; ui->label_pic->setPixmap(QPixmap::fromImage(image)); ui->label_pic->setScaledContents(true); index++; delay(); }
ui->label_pic->setText(tr("No More Images Avalable"));
}
-
Hi,
You might be having your loop running twice. You should modify your architecture and rather use a QTimer for your 5 second interval. Start it once you created your list and stop it before you create it.
-
Yes, rather than use a while loop like that, use a QTimer