1.把CMakeList.txt里面的find_package(qt4 required)替换成了find_package(Qt5Widgets)
如果你的Cmake报错:
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindQt4.cmake:664 (message):
Could NOT find QtCore.
Check D:/chen/CMakeFiles/CMakeError.log for more details.
参考:Detecting Qt5 with CMake
2.删去INCLUDE(${QT_USE_FILE})
将TARGET_LINK_LIBRARIES后面括号里面的${QT_LIBRARIES}删去
将target_link_libraries simpleTree Qt5::Widgets加入到addLibrary后面(其中simpleTree是你要编译的项目名字,在CMakeList里面找一下,出现了很多次)
如果你的CMake报错:
CMake Error at CMakeLists.txt:36 (INCLUDE):
include called with wrong number of arguments. Include only takes one
file.
参考:
Cmake and QT5 - Include only takes one argument
Implementing Qt project through CMake
3.QT4_WRAP_CPP(HEADERS_MOC ${INCLUDE_FILES})
QT4_WRAP_UI(FORMS_HEADERS ${FORMS})
QT4_ADD_RESOURCES(RESOURCES_RCC ${RESOURCES})
里面的4都改成5
如果你的CMake报错:
Unknown CMake command "QT4_WRAP_CPP".
4、把*.cmake文件里面的FIND_PACKAGE(Qt4 COMPONENTS QtCore QtXml QtOpenGL QtGui)替换成
FIND_PACKAGE(Qt5 QUIET COMPONENTS Core Xml OpenGL Gui Widgets)
这里还是报错findqt4有问题。