void Album::NextOne()
{
index++;
// 列出dir(path)目录文件下所有文件和目录信息,存储到imgInfoList容器
int count=imgInfoList.count();
if(index==count&&count>0)//回到第一张
{
index=0;
}
if(index > count && count==0)
{
index=0;
//qDebug() << "count: " << count << "index: " << index;
return;
}
if(index<0)
{
index=0;
return;
}
fileName.clear();
fileName.append(path);
fileName+="/home/haha/qtcode/VideoMonitor/Album/";
fileName+=imgInfoList.at(index).fileName();
//qDebug() << "filname: " << fileName;
QImage image;
if(!image.load(fileName))
{
QMessageBox::information(this,tr("Error"),tr("Open picture failed"));
return ;
}
image = image.scaled(Picture_WIDTH,Picture_HIGHT);
QPixmap pixmap=QPixmap::fromImage(image);
QSize imageSize=pixmap.size();
Picture_Label->setPixmap(pixmap);
Picture_Label->resize(imageSize);
qDebug()<<"fileName:"<<fileName;
setWindowTitle(QFileInfo(fileName).fileName());
}
void Album::LastOne()
{
index--;
// 列出dir(path)目录文件下所有文件和目录信息,存储到imgInfoList容器
int count=imgInfoList.count();
if (index < 0 && count==0)
{
index = 0;
//qDebug() << " count: " << count << "index: " << index;
return;
}
if (index < 0 && count>0) {
index = count-1;//数组要减1
//qDebug() << "count: " << count << "index: " << index;
}
if(index >= count)
{
index=0;
return;
}
fileName.clear();
fileName.append(path);
fileName+="/home/haha/qtcode/VideoMonitor/Album/";
fileName+=imgInfoList.at(index).fileName();
qDebug() << "filname: " << fileName;
QImage image;
if(!image.load(fileName))
{
QMessageBox::information(this,tr("Error"),tr("Open picture failed"));
return ;
}
image = image.scaled(Picture_WIDTH,Picture_HIGHT);
QPixmap pixmap=QPixmap::fromImage(image);
QSize imageSize=pixmap.size();
Picture_Label->setPixmap(pixmap);
Picture_Label->resize(imageSize);
qDebug()<<"fileName:"<<fileName;
setWindowTitle(QFileInfo(fileName).fileName());
}
列表加减1判断,及linux文件路径读取和改变写法