vs2015使用qt静态库5.7

MFC库现在基本上没落了, 用的人越来越少,现在一般做GUI开发都是使用Qt,  Qt这个东西实现比MFC不知道高到哪里去了, 使用起来更符合直觉, 学起来更简单,可惜了没有一个好爹, 一直没有火起来!!

Qt这个GUI库还是比较好用的, 只是在Windows上没有办法静态编译,每次发布都要带一堆的东西, 比较恶心!!这两天实在受不了了, 倒腾了一下Qt的静态编译。

1.下载Qt静态库

虽然Qt官方没有发布Qt的静态编译版本, 但是网上有爱好者自己把Qt的各个版本静态库编译好了, 直接下载就可以用。 省去了自己编译的麻烦!!

http://www.npcglib.org/~stathis/blog/precompiled-qt4-qt5/
编译的版本算是比较完整的, 我下载的是 Qt5 v5.7.0 (MSVC2015) 下载然后配置项目。
2.安装Qt5 Package

在vs2015的“扩展和更新”中寻找《Qt5Package》这个扩展,或者在下面网站下载然后安装,并重启

http://download.qt.io/development_releases/vsaddin/
打开扩展QT5,配置QT静态库中的bin目录,然后Reinstall template……

3.配置项目

虽然利用扩展给我们创建了一个项目模版,但是这个模版只能使用qt的动态库,静态库无法使用,  如果想编译静态编译,需要配置以下信息:

首先,在“链接器”-》“常规”-》“附加库目录”-》添加《$(QTDIR)\plugins\platforms》这个目录,即平台扩展静态库。

在“链接器”-》“输入”-》“附加依赖项”-》新增下面这些库
release 版本
qtmain.lib
Qt5Core.lib
Qt5Gui.lib
Qt5Widgets.lib
//—————————————————————————
Qt5PlatformSupport.lib
qminimal.lib
qoffscreen.lib
qwindows.lib
qtfreetype.lib
qtharfbuzzng.lib
qtpcre.lib
imm32.lib
winmm.lib
opengl32.lib
ws2_32.lib

debug

qtmaind.lib
Qt5Cored.lib
Qt5Guid.lib
Qt5Widgetsd.lib
//—————————————————————————

Qt5PlatformSupportd.lib
qminimald.lib
qoffscreend.lib
qwindowsd.lib
qtfreetyped.lib
qtharfbuzzngd.lib
qtpcred.lib
imm32.lib
winmm.lib
opengl32.lib
ws2_32.lib

4 文件依赖

在项目中找到main.cpp这个文件,在开头插入下面的代码,即可导入平台扩展静态库的头文件

#include <QtPlugin>
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)

如果是release版本,要在“代码生成”-》“运行库”,选择MT,debug为MTD

如果要兼容xp,平台工具集-》选择《v140_xp》
5 附加目录
首先,在“链接器”-》“常规”-》“附加库目录”-》添加《$(QTDIR)\plugins\platforms》这个目录,即平台扩展静态库

在C/C++->常规-》附加包含目录-》加入下面4个路径

$(QTDIR)\include\QtCore
$(QTDIR)\include\QtGui
$(QTDIR)\include\QtWidgets

$(QTDIR)\include\QtPlatformSupport

这样做完基本上就可以在windows上编译出来静态版本的Qt程序了, 只有一个exe不需要依赖一堆dll。 但是编译出来的文件也不小, 我使用x64版本的vs2015 debug版本编译出来20M release编译出来10M。。。。。 看来想要更下只能使用upx压缩一下了!

6.Qt Creator配置

如果是用QtCreator的话, 就比较简单了, 只需要添加一个版本,选项》构建套件和编译器里面添加一个配置, 然后在新建项目的时候选择我们安装的构建套件和编译器就行!

 

参考链接

http://blog.csdn.net/wyansai/article/details/51178631

http://blog.csdn.net/wsj18808050/article/details/50909381

网友评论:

  1. Johns Hopkins University Assignment Help 说:

    My friend recommended this blog and he was totally right keep up the fantastic work!

  2. Massachusetts Institute of Technology Assignment Help 说:

    Really i appreciate the effort you made to share the knowledge. This is really a great stuff for sharing. Keep it up . Thanks for sharing.

  3. Northwestern University Assignment Help 说:

    They are not able to finish the writing assignments on time. For some students, writing any writing assignments is able to waste their time

  4. Harvard Ocean Carriers Case solution 说:

    Well thanks for posting such an outstanding idea. I like this blog & I like the topic and thinking of making it right.

  5. Programming Assignment Help 说:

    I’m really impressed with your article, such great & usefull knowledge you mentioned here

  6. pay me to do exam 说:

    Thanks a lot for the post. It has helped me get some nice ideas. I hope I will see some really good result soon.

  7. Princeton University Assignment Help 说:

    This is really a great stuff for sharing. Keep it up .Thanks for sharing.

  8. Stanford University Assignment Help 说:

    I loved the way you discuss the topic great work thanks for the share Your informative post.

  9. Syracuse University Assignment Help 说:

    My friend recommended this blog and he was totally right keep up the fantastic work!

  10. Texas A&M University Assignment Help 说:

    Really i appreciate the effort you made to share the knowledge. This is really a great stuff for sharing. Keep it up . Thanks for sharing.

  11. University Of Chicago Assignment Help 说:

    They are not able to finish the writing assignments on time. For some students, writing any writing assignments is able to waste their time

  12. Vanderbilt University Assignment Help 说:

    Well thanks for posting such an outstanding idea. I like this blog & I like the topic and thinking of making it right.

  13. Sling TV Save Money Coupon 2018 说:

    Unquestionably believe that which you said. Your favorite
    reason appeared to be on the internet the simplest thing to
    be aware of. I say to you, I definitely get irked while people think about worries that they
    just do not know about. You managed to hit the nail upon the top and defined out the whole thing without having
    side effect , people could take a signal. Will
    probably be back to get more. Thanks

发表评论

发表评论前,请选对水果: 香蕉