我想在Qt中制作一组图像,但我不知道如何处理相同的图像。
我想在一个事件的小部件中加载数组中的图像。
任何帮助将不胜感激。
答案 0 :(得分:3)
Qt QImage
使用隐式数据共享,因此您可以传递它们并在数据结构中使用它们,例如您使用int
或QString
。
所以,QImage
数组就像你做int
数组......
但是,如果你不特别想要 array ,那么Qt中最常见的解决方案可能最适合你的情况QList
(注意:它不是链表,它是可调整大小的数组,非常像std::vector
):
QList<QImage> myImages;
答案 1 :(得分:1)
QImage img1("C:\\img1.jpg");
QImage img2("C:\\img2.jpg");
QImage img3("C:\\img3.jpg");
使用std::vector
:
std::vector<QImage> img_array;
img_array.push_back(img1);
img_array.push_back(img2);
img_array.push_back(img3);
或QVector
:
QVector<QImage> img_array;
img_array.push_back(img1);
img_array.push_back(img2);
img_array.push_back(img3);
答案 2 :(得分:1)
你可以简单地制作QImages的QList。 所以我会这样做:
// for simplicity
typedef QList<QImage> QImageList;
// allocate the list
QImageList imageList;
// create a list where you will put paths of your images
QStringList paths;
// then create the list of images
for(int i=0;i<paths.size();++i){
imageList.push_back(QImage(paths.at(i));
}