stlcours:如果你直接操作windows缓存文件,那么少一些是必然的,办法。。。。。可以使用winapi更新缓存,然后再。。。。
如果不是直接操作缓存,那图片少就是你自己的问题。你代码一个字都不贴,我也没办法帮你。

没有操作缓存文件,我是自己弄一个文件夹,然后把原来图片文件的缩略图放在这个文件夹里面,生成缩略图用的后台线程。。
这个是线程的run函数
void Thread::run()
{
smallImg = bigImg.scaled(IMG_H*4,IMG_W*4).
scaled(IMG_H,IMG_W,Qt::IgnoreAspectRatio,
Qt::SmoothTransformation);
smallImg.save(savePath); }
缓存的时候这样
void ImgCache::createCache(QString target,QString source)
{
QDir targetDir(target);
if(!targetDir.exists())
targetDir.mkpath(target);
QDir sourceDir(source);
QStringList filter;
filter<<"*"<<"*.png"<<"*.jpg"<<"*.jpeg"<<"*.ico"<<"*.bmp";
QFileInfoList list =
sourceDir.entryInfoList(filter,
QDir::Dirs|QDir::Files|
QDir::NoDotAndDotDot,
QDir::DirsFirst|QDir::Name);
foreach(QFileInfo info,list)
{
if(info.isFile())
{
QString savePath = target+"/"+info.fileName();
QImage img(info.filePath());
if(!img.isNull())
{
// QImage small = img.scaled(IMG_H*4,IMG_W*4).scaled(IMG_H,IMG_W,Qt::IgnoreAspectRatio,
// Qt::SmoothTransformation);
// small.save(savePath);
Thread *thread = new Thread(img,savePath);
QObject::connect(thread,Thread::finished,
this,ImgCahce::deleteThread);
thread->start();
}
}
if(info.isDir())
{
QString sourceSuffix =
info.filePath().remove(sourceRoot);
QString targetdir = targetRoot+sourceSuffix;
createCache(targetdir,info.filePath());
}
}
}
大概就这样,我用线程就不行,有缺失,报QImage::Scaled:image is a null image的错
但是用注释掉的那部分代码就不会有错,而且也没有缺失文件的现象。