`
qvb3d
  • 浏览: 171196 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

qt4 显示一个jpg图片

 
阅读更多

用qt4 显示一个jpg图片

1.资源文件准备

  ico.ico  程序图标
  open.jpg 程序要显示的图片

2.资源文件建立
 
  ico.rc
  以下是内容

  A ICON MOVEABLE PURE LOADONCALL DISCARDABLE "ico.ico"
 
  保存

  bitmap.qrc

  以下是内容

  <RCC>
 <qresource prefix="/images">
  <file>ico.ico</file>
  <file>open.jpg</file>
 </qresource> 
  </RCC>

  保存

这里建立两个资源文件ico.rc  bitmap.qrc

3.qt 显示程序

以下是内容


#include <QWidget.h>
#include <QPainter.h>
#include <QPen.h>
#include <QPixmap.h>
#include <QLabel.h>
#include <QApplication>
int main(int argc, char **argv)
{
    Q_INIT_RESOURCE(bitmap);
    QApplication app(argc, argv);
    QWidget qvbmain;
    QLabel *tmp1=new QLabel(&qvbmain);
    tmp1->setPixmap(QPixmap(":images/open.jpg"));
    //qvbmain.showMaximized();
    qvbmain.showFullScreen();
    return app.exec();
}

保存
4.生成项目

  qmake -project
  qmake

5.修改Makefile或是Makefile.release

 
$(DESTDIR_TARGET):  $(OBJECTS)
加入
用tab空位
 windres --input-format=rc -O coff -i ico.rc -o ico.res
修改
 $(LINK) ico.res $(LFLAGS) -o $(DESTDIR_TARGET) $(OBJECTS)  $(LIBS) -mwindows

结果为

$(DESTDIR_TARGET):  $(OBJECTS)
 windres --input-format=rc -O coff -i ico.rc -o ico.res
 $(LINK) ico.res $(LFLAGS) -o $(DESTDIR_TARGET) $(OBJECTS)  $(LIBS) -mwindows

保存

mingw32-make -f Makefile.release

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics