Clion 搭建Qt projects

news/2024/7/16 7:50:46 标签: qt, c++, ide

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工程。

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(
    helloworld
    main.cpp mainwindow.cpp
    application.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.niftyadmin.cn/n/5153753.html

相关文章

分享68个工作总结PPT,总有一款适合您

分享68个工作总结PPT,总有一款适合您 PPT下载链接:https://pan.baidu.com/s/1juus0gmesBFxJ-5KZgSMdQ?pwd8888 提取码:8888 Python采集代码下载链接:采集代码.zip - 蓝奏云 学习知识费力气,收集整理更不易。知识付…

dupeGuru 清理微信重复文件

本文摘录于:https://www.bilibili.com/video/BV13p4y1G75Y/?spm_id_from333.337.search-card.all.click&vd_source483e5c52353ea59d1a5eadac7737591a只是做学习备份之用,绝无抄袭之意,有疑惑请联系本人! 微信用了七八年,文件…

基于java+springboot+vue城市轨道交通线路查询系统-公交车线路查询

项目介绍 本系统是针对目前交通管理的实际需求,从实际工作出发,对过去的市轨道交通线路查询系统存在的问题进行分析,完善用户的使用体会。采用计算机系统来管理信息,取代人工管理模式,查询便利,信息准确率…

【网安AIGC专题11.1】论文12:理解和解释代码,GPT-3大型语言模型学生创建的代码解释比较+错误代码的解释(是否可以发现并改正)

Comparing Code Explanations Created by Students and Large Language Models 写在最前面总结思考 背景介绍编程教育—代码理解和解释技能培养编程教育—解决方案研究问题研究结果 相关工作Code ComprehensionPedagogical Benifis of code explanationLarge Language Models i…

UE5——源码阅读——1

UE启动 hInInstance :项目实例 hPrevInstance:项目上一个实例 pCmdLine:参数 nCmdShow:窗口显示 TRACE_BOOKMARK(TEXT(“WinMain.Enter”));:UE用来追踪记录的函数,用于标记应用程序在执行过程中一些特定的…

标签识别中的数据泄露:关键分析

一、介绍 在数据驱动的决策时代,收集、处理和分析数据的过程在从医疗保健到金融,从营销到研究的各个领域都发挥着举足轻重的作用。数据分析的基本步骤之一是正确识别数据集中的标签或类别。然而,这项看似简单的任务可能充满挑战,尤…

5 ip的分配

如上一节所述,需要和其他设备通信,那么需要先配置ip. 1、如何配置ip 1.可以使用 ifconfig,也可以使用 ip addr 2.设置好了以后,用这两个命令,将网卡 up 一下,就可以了 //---------------------------- 使…

【蓝桥杯省赛真题43】Scratch神奇哈哈镜 蓝桥杯少儿编程scratch图形化编程 蓝桥杯省赛真题讲解

目录 scratch神奇哈哈镜 一、题目要求 编程实现 二、案例分析 1、角色分析