Qt6.3 + Clion +MSVC2019環境配置詳解

1. VS2022中下載2019的編譯環境

在這裡插入圖片描述

2. Clion中配置工具鏈

在這裡插入圖片描述

註意選amd64

3. CMake選擇MSVC工具鏈

在這裡插入圖片描述

4. 編寫CMakeLists.txt

cmake_minimum_required(VERSION 3.5)

project(Pentagram VERSION 0.1 LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

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

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(QT_PATH "$ENV{QT6_DIR}")
set(CMAKE_PREFIX_PATH ${QT_PATH}) #這裡需要填入自己安裝的路徑


find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets LinguistTools)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets LinguistTools)

aux_source_directory(. DIRS_SRCS)  # 當前文件夾加入cmake
aux_source_directory(ui DIRS_SRCS)  # 當前文件夾加入cmake

set(SOURCE_FILES
        ${DIRS_SRCS}
        )
        
set(PROJECT_SOURCES
        ${SOURCE_FILES}
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(Pentagram
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
    )
    qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR})
else()
    if(ANDROID)
        add_library(Pentagram SHARED
            ${PROJECT_SOURCES}
        )
# Define properties for Android with Qt 5 after find_package() calls as:
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(Pentagram
            ${PROJECT_SOURCES}
        )
    endif()

    qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
endif()

target_link_libraries(Pentagram PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)

set_target_properties(Pentagram PROPERTIES
    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
#    WIN32_EXECUTABLE TRUE  # 去掉註釋則保留控制臺, 可以看到輸出
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(Pentagram)
endif()


5. 配置環境變量

在這裡插入圖片描述

6 完事

到此這篇關於Qt6.3 + Clion +MSVC2019環境配置詳解的文章就介紹到這瞭,更多相關Qt6.3 MSVC2019環境配置內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!

推薦閱讀: