mrg95
mrg95

Reputation: 2418

(Qt C++) Fill QMap with value and declare/initialize at same time?

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 :)

Upvotes: 0

Views: 1842

Answers (1)

ROTOGG
ROTOGG

Reputation: 1136

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");

Upvotes: 1

Related Questions