[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"));

    }


  • Lifetime Qt Champion

    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.



  • hello,
    It is now working as I wanted so thank you for your help.
    But you said my loop is running twice so is there any another way I can stop the previous loop from executing when same signal is generated again.


  • Lifetime Qt Champion

    Yes, rather than use a while loop like that, use a QTimer


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.