问题
I have created a Qt interface, add a Qlabel and set pixmap to an image. imagelabel =
new QLabel(centralwidget);
imagelabel->setObjectName(QString::fromUtf8("imagelabel"));
imagelabel->setGeometry(QRect(20, 10, 371, 311));
imagelabel->setPixmap(QPixmap(QString::fromUtf8(":/liqi/kinect.png")));
this is the code displayed in ui_mainwindow.h when i preview it using the Qtdesigner, the image can be displayed. But when i run using codeblocks, everything like buttons etc is fine but the image does not appear. Do i need to add anything into the section below ?
MainWindow::MainWindow(Tqt_interface* tqt, QWidget *parent ) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
回答1:
":/liqi/kinect.png"
':' means you are trying to open image that is included as resource. Make sure u have .qrc
file and it is added in .pro
project file. Like:
RESOURCES += res.qrc
Also make sure that image is in the .qrc
file.
来源:https://stackoverflow.com/questions/7674606/displaying-an-image-in-qlabel