@SeppJ Pointer vergleichen funktioniert nicht weil sich das QLabel bei setPixmap() seine eigene Kopie macht.
QtGuiApplication1.h
#pragma once
#include <QtWidgets/QDialog>
#include "ui_QtGuiApplication1.h"
class QtGuiApplication1 : public QDialog
{
Q_OBJECT
public:
QtGuiApplication1(QWidget *parent = Q_NULLPTR);
private:
Ui::QtGuiApplication1Class ui;
QPixmap sad_smiley;
QPixmap happy_smiley;
private slots:
void set_sad_smiley();
void set_happy_smiley();
void which_smiley();
};
QtGuiApplication1.cpp
#include "QtGuiApplication1.h"
#include <QMessageBox>
QtGuiApplication1::QtGuiApplication1(QWidget *parent)
: QDialog { parent },
sad_smiley { "sad_smiley.png" },
happy_smiley { "happy_smiley.png" }
{
ui.setupUi(this);
connect(ui.pushButtonLoadSadSmiley, SIGNAL(released()), this, SLOT(set_sad_smiley()) );
connect(ui.pushButtonLoadHappySmiley, SIGNAL(released()), this, SLOT(set_happy_smiley()) );
connect(ui.pushButtonWhichSmiley, SIGNAL(released()), this, SLOT(which_smiley()) );
}
void QtGuiApplication1::set_sad_smiley()
{
ui.label->setPixmap(sad_smiley);
}
void QtGuiApplication1::set_happy_smiley()
{
ui.label->setPixmap(happy_smiley);
}
void QtGuiApplication1::which_smiley()
{
QMessageBox message_box;
message_box.setWindowTitle("Smiley Info:");
if (!ui.label->pixmap()) {
message_box.setText("No Picture");
message_box.exec();
return;
}
QImage image_from_label{ ui.label->pixmap()->toImage() };
if ( image_from_label == sad_smiley.toImage()) {
message_box.setText("Sad Smiley :(");
}
else if (image_from_label == happy_smiley.toImage()) {
message_box.setText("Happy Smiley :)");
}
else {
message_box.setText("No Smiley _._");
}
message_box.exec();
}
ui_QtGuiApplication1.h
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QtGuiApplication1Class</class>
<widget class="QDialog" name="QtGuiApplication1Class">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>670</width>
<height>475</height>
</rect>
</property>
<property name="windowTitle">
<string>QtGuiApplication1</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>60</x>
<y>40</y>
<width>400</width>
<height>400</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="text">
<string/>
</property>
</widget>
<widget class="QPushButton" name="pushButtonLoadSadSmiley">
<property name="geometry">
<rect>
<x>510</x>
<y>50</y>
<width>111</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Set Sad Smiley</string>
</property>
</widget>
<widget class="QPushButton" name="pushButtonLoadHappySmiley">
<property name="geometry">
<rect>
<x>510</x>
<y>80</y>
<width>111</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Set Happy Smiley</string>
</property>
</widget>
<widget class="QPushButton" name="pushButtonWhichSmiley">
<property name="geometry">
<rect>
<x>510</x>
<y>110</y>
<width>111</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Which Smiley?</string>
</property>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
<include location="QtGuiApplication1.qrc"/>
</resources>
<connections/>
</ui>
happy_smiley.png
sad_smiley.png
Vielleicht reicht es für Dein Vorhaben auch, die QPixmap::cacheKey()s zu vergleichen.