VS2015配置Qt5

须要准备的东西

  • Visual Studio 2015
  • Qt5
  • VS2015 Qt插件

系统:win7/win10都可windows

VS2015

最新的Qt是Qt5.13,只支持VS2015,VS2017。为了兼容性考虑这里装的VS2015。工具

Qt5

从官网下载:https://download.qt.io/archive/qt/5.13/5.13.0/qt-opensource-windows-x86-5.13.0.exe 用迅雷加速
ui

勾选vs2015, VS2017支持。这里找了一个早期版本的qt的截图:
.net

VS2015 Qt插件

菜单栏->工具->扩展和更新->联机,搜索qt,安装,而后重启vs2015
装好Qt5后,菜单栏->QT TOOLS->options,配置qt5的vs2015的路径插件

rc.exe没法启动

VS里新建Qt工程code

参考:
https://blog.csdn.net/wb175208/article/details/83418716htm

每一个人的VS安装路径可能不同。我是:blog

C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x86\rc.exe
C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x86\rcdll.dll

拷贝到:ip

D:\soft\Microsoft Visual Studio 14.0\VC\bin

基于CMake的Qt工程

首先考虑最简单的Helloworld工程。我是先在VS里建好Qt的helloworld工程 而后把生成的几个文件拷贝到新的目录中,而后新建CMakeLists.txt:

cmake_minimum_required(VERSION 3.1.0)

project(helloworld)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

find_package(Qt5 COMPONENTS Widgets REQUIRED)

add_executable(helloworld
    src/QtGuiApplication.ui
    src/QtGuiApplication.cpp
    src/main.cpp
    src/QtGuiApplication.qrc
)

target_link_libraries(helloworld Qt5::Widgets)

add_custom_command(TARGET helloworld POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Qt5::Core> $<TARGET_FILE_DIR:helloworld>
    COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Qt5::Gui> $<TARGET_FILE_DIR:helloworld>
    COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:Qt5::Widgets> $<TARGET_FILE_DIR:helloworld>
)

其中src/目录下的几个文件是拷贝过来的。拷贝dll的操做参考了[2]

reference

[1] http://www.javashuo.com/article/p-qwoubnkv-bh.html

[2] Qt5 dll copy example