PDA

View Full Version : Image Viewer for multiple images



sinha.ashish
25th April 2008, 10:53
I am having name of images in a stringlist "imageList", stringlist "imageTypeList" to hold type of images and size of this list in "imageListSize" now i want to view the images one after other at the time lag of 5 seconds,i have written code to implement this,my images were residing on the server :

void Viewer::imageViewer()
{
timer->stop();
if(!imageList.isEmpty())
{
if(imageListSize>=0)
{
buffer.open(QIODevice::ReadWrite);
QString fileName = imagelist[imageListSize];
imageftp=new QFtp(this);
imageftp->connectToHost("190.111.111.1");
imageftp->login("user","passwd");
imageftp->cd("media");
imageftp->get(fileName, &buffer);
connect(imageftp, SIGNAL(commandFinished(int, bool)),this, SLOT(ftpCommandFinished(int, bool)));
}
}

}



void Viewer::ftpCommandFinished(int, bool)
{
timer=new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(imageViewer()));
timer->start(5000);
buffer.open(QIODevice::ReadWrite);
QByteArray data=buffer.data();
QByteArray type;
type.insert(0,imageTypeList[imageListSize]);
if(!imageftp->hasPendingCommands())
{
QImageReader reader(&buffer, type);
QImage image = reader.read();
imageui.imageLabel->setPixmap(QPixmap::fromImage(image));
idialog.show();
}
imageListSize--;
imageViewer();
}


Above code produces segmentation fault,help me out...

Shadowfiend
25th April 2008, 16:30
At a glance, it seems like the timer is initialized in ftpCommandFinished, but is stopped in imageViewer. Does the timer variable have a default value the first time imageViewer() is called?