Displaying an image in QLabel

≯℡__Kan透↙ 提交于 2020-01-06 08:51:09

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!