当前位置: 首页 > news >正文

Clion 搭建Qt projects

Qt projects

Qt is a cross-platform C++ framework for creating GUI applications. Qt uses its own build system, qmake, and also supports building with CMake starting from the version Qt4.

Qt是一款创建桌面程序的跨平台的C++框架。qmake是Qt自有的构建系统,从Qt4版本开始,Qt系统开始支持CMake进行构建。

A pure Qmake project can't be imported in CLion directly. However, when converted into CMake, it can be opened and managed as a regular CMake application. You can also create a CMake-based Qt project in CLion using the New Project wizard.

CLion无法直接引入由qmake创建的项目,但是可以打开从qmake转换成cmake的Qt项目。开发人员也可以通过CLion的工程向导创建基于CMake的Qt工程。

CMake-based Qt projects

For CMake version 3.0 and newer, Qt ships the modules that let CMake find and use Qt4 and Qt5 libraries. Take the following steps to configure CMakeLists.txt for your Qt project.

对于CMake 3.0及更新版本,CMake 查找Qt模块并使用 Qt4 和 Qt5 库。请按以下步骤为您的 Qt 项目配置 CMakeLists.txt。

CMakeLists.txt for a Qt project

Qt项目的CMakeList.txt文件

  • Add the find_package command to locate the required libraries and header files. For example:

 添加find_package命令定位查找所需的库文件和头文件,例如:

find_package(Qt5Widgets REQUIRED)

Then, use target_link_libraries to make your target dependent on these libraries and headers:

随后,使用target_link_libraries命令将你的目标绑定查找到的库文件和头文件。

target_link_libraries(helloworld Qt5::Widgets)
  • For find_package to perform successfully, CMake should be instructed on where to find the Qt installation.

      当find_package命令运行成功后,接下来给CMake配置Qt的安装配置。

One of the ways to do this is by setting the CMAKE_PREFIX_PATH variable. You can either pass it via -D in the CMake settings dialog or via the set command before find_package.

一种方式是通过给CMake设定CMAKE_PREFIX_PATH变量。这种设定方式既可以通过在CMake的设置对话框中传入“-D”或者在find_package命令之前通过set命令设置。

For example, in the case of MinGW on Windows:

例如,在Windows系统中设置MinGW:

set(CMAKE_PREFIX_PATH "C:\\Qt\\Qt5.14.0\\5.14.0\\mingw73_32\\")

或者

set(CMAKE_PREFIX_PATH "C:\\Qt\\Qt5.14.0\\5.14.0\\mingw73_32\\lib\\cmake\\")
  • If your project uses MOC, UIC, or RCC, add the following lines to enable automatic invocation of the corresponding compilers:

    如果项目中使用到MOC、UIC或者RCC,请添加以下命令启动相应的编译器:

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
  • List all the .ui and .qrc files in the add_executable() command along with your .cpp sources:

   在add_executable()命令列出你的“.cpp”文件、“.ui”文件和“.qrc”文件。

add_executable(helloworldmain.cpp mainwindow.cppapplication.qrc
)

Below you can find the full CMakeLists.txt script for a simple "Hello, world" application:

下面列出了“Hello, world”程序所需的CMakeList.txt脚本:

cmake_minimum_required(VERSION 3.10)
project(Qt-CMake-HelloWorld)set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_PREFIX_PATH "C:\\Qt\\Qt5.14.0\\5.14.0\\mingw73_32\\")find_package(Qt5Widgets REQUIRED)set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)add_executable(helloworld main.cpp mainwindow.cpp application.qrc)
target_link_libraries(helloworld Qt5::Widgets)

https://www.jetbrains.com/help/clion/qt-tutorial.html


http://www.lryc.cn/news/223218.html

相关文章:

  • 合肥工业大学数据库实验报告
  • 设计模式-装饰器模式(Decorator)
  • Java 数据结构篇-实现双链表的核心API
  • 电脑如何截屏?一起来揭晓答案!
  • 【实战-08】flink 消费kafka自定义序列化
  • 深入浅出 Django 异步编程
  • 力扣 138. 随机链表的复制
  • STM32外部中断大问题
  • FPGA配置采集AR0135工业相机,提供2套工程源码和技术支持
  • KubeSphere v3.4.0 部署K8S Docker + Prometheus + grafana
  • Codeforces Round 908 (Div. 2)题解
  • Redis笔记 Redis主从同步
  • 数据结构-Prim算法构造无向图的最小生成树
  • MFC串口通信(SerialPort)
  • Vim基本使用操作
  • 【深蓝学院】手写VIO第8章--相机与IMU时间戳同步--作业
  • Naocs配置中心配置映射List、Map、Map嵌套List等方式
  • 如何通过CRM系统进行销售机会管理?
  • 解决idea启动tomcat控制台中文乱码
  • vscode + cmake + opencv example
  • day57【动态规划】647.回文子串 516.最长回文子序列
  • 分享vmware和Oracle VM VirtualBox虚拟机的区别,简述哪一个更适合我?
  • YOLOV5模型运行
  • @Autowired和@Resource注解的区别和联系
  • 设计模式类型
  • Android修行手册-实现利用POI将图片插入到Excel中(文末送书)
  • 低功耗工业RFID设备应用
  • # Oracle 库常见问题排查
  • 矩阵乘积的迹对矩阵求导
  • IP 地址冲突检测工具