0

How could I fill a QMap value with a QPixmap and create that variable at the same time?

It's really hard for me to explain

What I currently have:

QMap<QString, QPixmap> slot_pic;

slot_pic["block1damage0"] = (QPixmap)b1d0(":/textures/blocks/textures/blocks/stone.png");

I get an error saying that QPixmap b1d0 is an undeclared identifier.

Obviously, I COULD do this:

QPixmap b1d0(":/textures/blocks/textures/blocks/stone.png");

slot_pic["block1damage0"] = b1d0;

The problem is I have around 400 of these, and I already gave each QPixmap a path, so I don't want to write everything again -_- It would be GREAT if I could fill the map as I am declaring each QPixmap path.

Thanks for you time. Feel free to comment as many questions as you like :)

mrg95
  • 2,371
  • 11
  • 46
  • 89
  • You know that you can iterate directories in resources? I hope you're not putting like 400 lines of slot_pic["hardcodedvarname"] = QPixmap(":hardcodedpathhere"); – Kamil Klimek Jul 15 '13 at 07:06

1 Answers1

1

Get rid of b1d0. Just create a temprary QPixmap and let the assignment operator of QPixmap run its course.

QMap<QString, QPixmap> slot_pic;
slot_pic["block1damage0"] = (QPixmap)(":/textures/blocks/textures/blocks/stone.png");
ROTOGG
  • 1,106
  • 1
  • 7
  • 17
  • I will try this, would it be possible to use a QMap with a key int, and a value QPushButton? – mrg95 Jul 14 '13 at 18:59