PDA

View Full Version : [solved]QImage Load issue



kamlmish
21st December 2010, 06:58
Hi
I have a small piece of code to load a list of images



void MainWindow::listdisplay()
{
QDir dir("/home/kamlesh/Gall/GALL/images/eBeam Gallery/Art & Design/2D Shapes");
dir.setFilter(QDir::Files);
QList<QImage> images;
QImage thumb, tmp;
int sizeW = 20;
int sizeH = 20;
QStringList listfiles = dir.entryList(QStringList()<<"*.png",QDir::Files);
for(int i=0;i<=listfiles.count();i++)
{

QString filename = listfiles.at(i);
bool x = tmp.load(filename);
//bool x = tmp.load("/home/kamlesh/Gall/GALL/images/eBeam Gallery/Art & Design/2D Shapes/Black Hexagon.png");
if(x == true){
thumb = (tmp.scaled( 1240, 1480 ).scaled( sizeW, sizeH, Qt::KeepAspectRatio )); //two passes
modl->setData( modl->index( i, 0 ), thumb, Qt::DecorationRole );}
}
//listwidget->addItems(listfiles);
viw->setModel(modl);
viw->show();

}



Issue is that , I am able to get the filename , but when I use
QImage::load(filename)
it returns FALSE value

Lykurg
21st December 2010, 07:09
have you debuged the content of filename? I guess it is only relative to dir. So you probably have to prepend that first.

kamlmish
21st December 2010, 08:11
Even after appending the full path, QImage::Load doesnt work



void MainWindow::listdisplay()
{
QDir dir("/home/kamlesh/Gall/GALL/images/eBeam Gallery/Art & Design/2D Shapes");
dir.setFilter(QDir::Files);
QList<QImage> images;
QImage thumb, tmp;
int sizeW = 20;
int sizeH = 20;
QStringList listfiles = dir.entryList(QStringList()<<"*.png",QDir::Files);
for(int i=0;i<=listfiles.count();i++)
{
QString filename = listfiles.at(i);
QString filepath = dir.absoluteFilePath(filename);
bool x = tmp.load(filepath);
//bool x = tmp.load("/home/kamlesh/Gall/GALL/images/eBeam Gallery/Art & Design/2D Shapes/Black Hexagon.png");
if(x == true)
{
thumb = (tmp.scaled( 1240, 1480 ).scaled( sizeW, sizeH, Qt::KeepAspectRatio )); //two passes
modl->setData( modl->index( i, 0 ), thumb, Qt::DecorationRole );
}

}


The images have been taken from MACOS, and the work environment is linux,qt
Is that the issue ?

oliverliu.hz
10th February 2011, 06:23
try use an easy directory instead of "/home/kamlesh/Gall/GALL/images/eBeam Gallery/Art & Design/2D Shapes/", such as "/tmp/1.png"
hope to help you.