[英]Displaying an image in QLabel
I have created a Qt interface, add a Qlabel and set pixmap to an image. 我创建了Qt界面,添加了Qlabel并将pixmap设置为图像。 imagelabel = 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. 这是当我使用Qtdesigner预览时在ui_mainwindow.h中显示的代码,可以显示图像。 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);
}
":/liqi/kinect.png"
':' means you are trying to open image that is included as resource. ":/liqi/kinect.png"
':'表示您正在尝试打开作为资源包含的图像。 Make sure u have .qrc
file and it is added in .pro
project file. 确保您有.qrc
文件,并将其添加到.pro
项目文件中。 Like: 喜欢:
RESOURCES += res.qrc
Also make sure that image is in the .qrc
file. 还要确保该图像位于.qrc
文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.