I think Qt qpixmap This class is very familiar to everyone, it can be very simple to map on the label, for example:
Qpixmap p;
P.load ("1.png");
Label->setpixmap (P);
It's that simple, but I suddenly find a problem today:
Qpixmap p;
P.load ("1.png");
Label->setpixmap (P);
P.load ("2.png");
Label->setpixmap (P);
P.load ("1.png");
Label->setpixmap (P);
When using the same p, which is the global variable, you load image 1, display picture 1; Reload image 2, display picture 2; But when you want to change back to the picture, you load the picture one, do not make it, do not come back, or show the picture two, you load a picture three, so that you want to change back to the picture two, not so ...
This is for God horse???
Originally, P.load () is to load the picture into the buffer: Qpixmapcache, when you load the picture two is, the picture is not overwritten, at this time the buffer has picture one and picture two, when you load the picture again, thought the buffer should have, so p.load (), Returns true directly, but the picture is still picture two, so it cannot be displayed back to the picture One!
The solution is simple and there are three ways to do it:
First, the direct definition of local variables, so that each time is a new buffer;
Second, when the picture is loaded again, the buffer is emptied first, qpixmapcache::clear (), and then loaded;
Three, in the initialization function write: Qpixmapcache::setcachelimit (1); Set the buffer can only put a picture, so that will replace the original picture, you can load new pictures!
[Go]-qpixmap global variable loading multiple pictures failure problem