1.把CMakeList.txt里面的find_package(qt4 required)替換成了find_package(Qt5Widgets)
如果你的Cmake報(bào)錯(cuò):
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后面括號(hào)里面的${QT_LIBRARIES}刪去
將target_link_libraries simpleTree Qt5::Widgets加入到addLibrary后面(其中simpleTree是你要編譯的項(xiàng)目名字,在CMakeList里面找一下,出現(xiàn)了很多次)
如果你的CMake報(bào)錯(cuò):
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報(bào)錯(cuò):
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)
這里還是報(bào)錯(cuò)findqt4有問題蒸甜。