- Take a form
- Place two CommandLinkButton(s) on the form
- Place a PushButton on the form
- Right click PushButton-> Go to slot...
- Choose clicked()
- Write following code:
std::cout << ui->commandLinkButton->icon().cacheKey() << std::endl;
std::cout << ui->commandLinkButton_2->icon().cacheKey() << std::endl;
Why does that code print two different values for the cachekey? We did not change the icon of any CommandLinkButton so both have the same default icon!
My problem is like this: I have a push button with an icon on it, which is coming from resources. I want to verify in test code that it has the same required icon on it.
To do that I compare the cachekey of image on the push button and cachekey of QPixmap object having same image like this:
const QPixmap image(":/MyProject/Images/Yellow_Icon_40x40.png");
if(image.cacheKey() == ui->PushButton->icon().cacheKey())
{
cout<<"OK";
}
But that test fails because cacheKey turns out to be different. So what is the best way to do that check? Basically like calculating hash of image and match that hash, which should always be same for any instance of same image.