Qt Label :: setPixmap不工作 [英] Qt Label::setPixmap not working

查看:414
本文介绍了Qt Label :: setPixmap不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单,我试图在一个简单的Qt GUI应用程序显示一个图像。
我有这个代码:

  ui-> label_2-> setVisible 
QPixmap supremect(:/ images / supremecourt.jpg);
ui-> label_2-> setPixmap(supremect);
if(supremect.isNull())
{
QMessageBox err(this);
err.setText(File null);
err.exec();
}
building = SPCT; // A flag
ui-> label_2-> show();

它编译完美,但当我运行它,没有显示。我确信图片存在于资源中,所以我做错了什么?



编辑:转换为PNG不起作用


<从一些IDE(Qt Creator)运行它并检查日志,然后从其中删除它。


  • 请确保已加载jpg插件。


  • 请确保其他内容不会更改标签内容(例如setText会清除pixmap)



  • Simple, I'm trying to display an image in a simple Qt GUI app. I have this code:

    ui->label_2->setVisible(true);
    QPixmap supremect(":/images/supremecourt.jpg");
    ui->label_2->setPixmap(supremect);
    if(supremect.isNull())
    {
        QMessageBox err(this);
        err.setText("File null");
        err.exec();
    }
    building=SPCT; // A flag
    ui->label_2->show();
    

    It compiles perfectly, but when I run it, nothing shows. I am sure that the image exists in the resources, so what am I doing wrong?

    EDIT: Converting to PNG does not help

    解决方案

    1. run it from some IDE (Qt Creator) and check logs. It is almost certain that some error message is shown there.

    2. make sure that jpg plug in is loaded.

    3. make sure that something else doesn't change content of label (for example setText will clear pixmap)

    这篇关于Qt Label :: setPixmap不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆