The widget that we should use to display images is QLabel. we can do this directly from QtCreator by setting its pixmap property.
we must first create the resource file and then add the image to this resource file. To create a Qt resource file, go to the menu: File> Qt> Qt Resource File.
we can install the QLabel image using Qt Creator ...
but I would like to change pic according to some user input
I tried to do the following:
#include "form1.h"
#include "form.h"
#include "ui_form.h"
#include "ui_form1.h"
Form::Form(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form)
{
ui->setupUi(this);
QPixmap * mypix = new QPixmap(":/karim/test.png");
ui->label->setPixmap(mypix);
delete mypix;
}
but i got this error
..\Project\form.cpp: In constructor 'Form::Form(QWidget*)':
..\Project\form.cpp:12: error: no matching function for call to 'QLabel::setPixmap(QPixmap*&)'
c:\QtSDK\Simulator\Qt\mingw\include/QtGui/qlabel.h:123: note: candidates are: void QLabel::setPixmap(const QPixmap&)
what could be the problem?
source
share