Mac Clion 下简单配置 Qt 开发环境

警告
本文最后更新于 2023-03-09,文中内容可能已过时。

要求

  • brew
  • Clion

步骤

  1. brew install qt@5
  2. 配置环境变量
1
2
3
4
# Qt5
export PATH="/usr/local/opt/qt@5/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/qt@5/lib"
export CPPFLAGS="-I/usr/local/opt/qt@5/include
  1. Clion 创建 qt 项目
    设置 Qt CMake prefix path 路径:/usr/local/Cellar/qt@5/5.15.5_1/lib/cmake

img
img

CmakLists.txt

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
cmake_minimum_required(VERSION 3.23)
project(demo1)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

set(CMAKE_PREFIX_PATH "/usr/local/Cellar/qt@5/5.15.5_1/lib/cmake")

find_package(Qt5 COMPONENTS
        Core
        Gui
        Widgets
        REQUIRED)

add_executable(demo1 main.cpp)
target_link_libraries(demo1
        Qt5::Core
        Qt5::Gui
        Qt5::Widgets
        )

效果

img
img

Buy Me a Coffee ~~
hiifong 支付宝支付宝
hiifong 微信微信
0%