• 3580阅读
  • 0回复

问一个有难度的问题..... [复制链接]

上一主题 下一主题
离线killua_hzl
 

只看楼主 倒序阅读 楼主  发表于: 2009-08-18
想要返回目录下所有图片的名字,然后可以上一张下一张的查看,不知道应该怎么写??

我自己写了一个版本不知道错在哪里,哪位大侠看看

下面是用来返回所有图片文件名
  1.     curfileName = QFileDialog::getOpenFileName(this, tr("Open File"),QDir::currentPath(),tr("Images (*.png *.bmp *.jpg)"));
  2.     QString path = QFileInfo(curfileName).absolutePath();
  3.     QDir dir(path);
  4.     QStringList filters;
  5.     filters<< "*.jpg" << "*.bmp" << "*.png";
  6.     fileList = dir.entryList(filters,QDir::Files,QDir::Name);


用来查询的代码
  1. /**
  2.   上一张图片
  3.   */
  4. void ImageViewer::preImage()
  5. {
  6.     int index = fileList.indexOf(curfileName);
  7.     curfileName = fileList.at(index - 1);
  8.     imageLabel->setPixmap(QPixmap::fromImage(image));
  9. }
  10. /**
  11.   下一张图片
  12.   */
  13. void ImageViewer::nextImage()
  14. {
  15.     int index = fileList.indexOf(curfileName);
  16.     curfileName = fileList.at(index + 1);
  17.     image.load(curfileName);
  18.     imageLabel->setPixmap(QPixmap::fromImage(image));
  19. }
  20. /**
  21.   第一张图片
  22.   */
  23. void ImageViewer::firstImage()
  24. {
  25.     curfileName = *fileList.begin();
  26.     image.load(curfileName);
  27.     imageLabel->setPixmap(QPixmap::fromImage(image));
  28. }
  29. /**
  30.   最后一张图片
  31.   */
  32. void ImageViewer::lastImage()
  33. {
  34.     curfileName = *fileList.end();
  35.     image.load(curfileName);
  36.     imageLabel->setPixmap(QPixmap::fromImage(image));
  37. }


我Debug过了,其中preImage和nextImage函数的index一直为-1,也就是说没有找到,请问大大这些代码哪里错了??
快速回复
限100 字节
 
上一个 下一个