Load images from a directory into QList<QPixmap>
-
QList>QPixmap> pixmaps; for( int i = 0; i < fileNames; ++i ) pixmaps << QPixmap(fileNames.at(i));
-
@raven-worx, thanks a lot for your help!
unfortunately it seems like I've got any mistake anyway.Here's the actual code:
QDir directory("C:/Users/.../references"); QList<QString> examples << "*.png"; QList<QString> exlist = directory.entryList(examples); for (int z = 0; z < exlist.size(); z++) { QList<QPixmap>exampleList << QPixmap(exlist.at(z)); } ui->exampleLabel->setPixmap(exampleList.at(3)); ui->exampleLabel->show();
Last two lines should show the Image with Index 3 at my label, but it doesn't work
-
@franad
I dont think that QDir::entryList() returns absolute paths but only the names? -
@raven-worx
when I do something likeexamplePixmap.load("references/"+exlist.at(0));
it works. "Works" means that I can show up my examplePixmap in a Label.
But if there is any other posibility to get the absolute paths of my files I would be fine with that.
Unfortunately I'm pretty new to qt... -
You're passing the path to QDir so why don't you use this? QDir also has e.g. QDir::absoulteFilePath() - http://doc.qt.io/qt-5/qdir.html#absoluteFilePath
-
thank you for your help! Could you please precise your hint a little bit?
-
@franad said in Load images from a directory into QList<QPixmap>:
for (const QString &fileName : exlist) exampleList.push_back(QPixmap(directory.absoluteFilePath(fileName));
-
Thanks a lot! Everythings seems fine now. Thank you