I want an Array of static Pixmaps in a class which extends QLabel.
I want some QLabels arranged in a parent widget, to easily show many pictures at one time, changing during runtime. In order to acces the hardrive only one time and saving memory, I would like to have these Pictures somehow stored as a static array, so that I can easily display new pictures by creating a QLabel and setting its pixmap to one of the pictures. (sounds confusing? look at the source code)
I tried this with QPixmap, if there is a better way for my plan, please tell me.
I tried the following (which doesn't work, but to give you an idea what I want to do. :
(I use php code tag since the highlight is better, it's ment to be C++)
|
PHP Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
#ifndef KARTENFLAECHE_H
#define KARTENFLAECHE_H
#include
class Kartenflaeche : public QLabel
{
Q_OBJECT
public:
Kartenflaeche(QWidget *parent = 0);
private:
static QPixmap Icons[3];
};
QPixmap Kartenflaeche::Icons[3] = {QPixmap("das.png"),QPixmap("das.png"),QPixmap("das.png")};
|
The application compiles, but the crashes since
QPixmap: Must construct a QApplication before a QPaintDevice
so I tried to initialize Icons in main.cpp
|
PHP Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#include
#include "Kartenflaeche.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget * w = new QWidget;
QPixmap Kartenflaeche::Icons[3] = {QPixmap("das.png"),QPixmap("das.png"),QPixmap("das.png")};
w->show();
return a.exec();
}
|
which results in an compiler error
|
Source code
|
1
2
3
4
5
6
7
8
|
../blackjack/main.cpp: In Funktion »int main(int, char**)«:
../blackjack/main.cpp:11:35: Fehler: ungültige Verwendung des qualifizierten Namens »Kartenflaeche::Icons«
make: *** [main.o] Fehler 1
make: Leaving directory `/home/mensch/Dokumente/blackjack-build-desktop'
The process "/usr/bin/make" exited with code 2.
Error while building project blackjack (target: Desktop)
When executing build step 'Make'
|
the error message translated is like: Error: invalid use of the qualified name
»Kartenflaeche::Icons«
How can I define a static private QPixmap, or rather is there a better way to build many QLabels sharing a static array of pictures?
Thank you for taking time to read and perhaps to awnser.