如果单击按钮,我希望在同一窗口中显示图像。但是找不到图片,不管是在同一个目录还是我写下整个路径。我看到了几种整合图片的方法,并认为这是最好的一种:
MyApp::MyApp(QWidget *parent)
: QWidget(parent)
{
QPushButton *button = new QPushButton("&Randomize!");
gitterlayout->addWidget(button, 5, 0);
connect(button, SIGNAL(clicked()), this, SLOT(Randomizer()));
}
void MyApp::Randomizer()
{
QLabel* bild = new QLabel;
QPixmap pixmap("question.png"); // the important part, the picture is in my project folder
if(!pixmap.isNull())
{
bild->setPixmap(pixmap);
bild->show();
}
else
{
qDebug() << "Cannot find picture"; // I always get this message
}
/* I want this question image to appear because once you click on the button,
a text will be copied to the clipboard and you can't see it until you paste it
(I left it out for this topic) */
}
如果我使用QPixmap pixmap("C:/myproject/question.png");
(完整路径)它也不起作用。