Qt(Ubuntu)静态编译无法显示图片

来源:互联网 发布:最终幻想14 mac 编辑:程序博客网 时间:2024/05/21 00:52

  • 前言
  • 解决方法
  • ps 动态编译无法显示图片的方法

前言

在使用静态编译发布QT程序时,发现无法显示ico格式的图片,png格式图片显示正常。主要原因是QT默认并不支持ico格式的图片,而是以插件的形式加载ico图片。

By default, Qt supports the following formats:

Format Description Qt’s support

BMP Windows Bitmap Read/write

GIF Graphic Interchange Format (optional) Read

JPG Joint Photographic Experts Group Read/write

JPEG Joint Photographic Experts Group Read/write

PNG Portable Network Graphics Read/write

PBM Portable Bitmap Read

PGM Portable Graymap Read

PPM Portable Pixmap Read/write

TIFF Tagged Image File Format Read/write

解决方法

  • 步骤1
    在Pro文件中加入ico插件库路径

    LIBS += /opt/Qt486_Static/plugins/imageformats/libqico.a
  • 步骤2
    在main文件中添加头文件:
    #include <QtPlugin>
    在main函数中导入库

    Q_IMPORT_PLUGIN(qico);
  • 步骤3
    重新编译项目

分割线


ps : 动态编译无法显示图片的方法

曾经将QT程序移植到ARM开发板上时也出现过png格式图片无法显示的问题,解决方法是:

将开发板QT安装目录下plugins/imageformats文件夹复制到运行目录下即可解决。

原创粉丝点击