想要返回目录下所有图片的名字,然后可以上一张下一张的查看,不知道应该怎么写??
我自己写了一个版本不知道错在哪里,哪位大侠看看
下面是用来返回所有图片文件名
- curfileName = QFileDialog::getOpenFileName(this, tr("Open File"),QDir::currentPath(),tr("Images (*.png *.bmp *.jpg)"));
- QString path = QFileInfo(curfileName).absolutePath();
- QDir dir(path);
- QStringList filters;
- filters<< "*.jpg" << "*.bmp" << "*.png";
- fileList = dir.entryList(filters,QDir::Files,QDir::Name);
用来查询的代码
- /**
- 上一张图片
- */
- void ImageViewer::preImage()
- {
- int index = fileList.indexOf(curfileName);
- curfileName = fileList.at(index - 1);
- imageLabel->setPixmap(QPixmap::fromImage(image));
- }
- /**
- 下一张图片
- */
- void ImageViewer::nextImage()
- {
- int index = fileList.indexOf(curfileName);
- curfileName = fileList.at(index + 1);
- image.load(curfileName);
- imageLabel->setPixmap(QPixmap::fromImage(image));
- }
- /**
- 第一张图片
- */
- void ImageViewer::firstImage()
- {
- curfileName = *fileList.begin();
- image.load(curfileName);
- imageLabel->setPixmap(QPixmap::fromImage(image));
- }
- /**
- 最后一张图片
- */
- void ImageViewer::lastImage()
- {
- curfileName = *fileList.end();
- image.load(curfileName);
- imageLabel->setPixmap(QPixmap::fromImage(image));
- }
我Debug过了,其中preImage和nextImage函数的index一直为-1,也就是说没有找到,请问大大这些代码哪里错了??