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

ubuntu 使用 CMake 构建 Qt5 项目

Qt 概述

  1. 概念

Qt 是一个跨平台的 C++ 图形用户界面应用程序框架

常见的 C++ GUI: Qt 和 MFC

  1. 跨平台
  • Windows

  • Linux

  • MacOS

  • 嵌入式平台

  1. 版本

包括商业版和开源免费版

  1. 案例
  • Linux 桌面环境 KDE

  • WPS Office

Qt 安装

下载地址:

  • https://download.qt.io/archive/qt/

  • https://www.qt.io/download-open-source

构建 Qt 项目

参考: https://doc.qt.io/qt-5/cmake-get-started.html

新建一个目录 Begin, 在该目录下新建 CMakeLists.txt, main.cpp 以及 build 空目录

Begin/
├── build
├── CMakeLists.txt
└── main.cpp

1 directory, 2 files

  • CMakeLists.txt 的内容:
cmake_minimum_required(VERSION 3.10)project(Begin)set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_PREFIX_PATH /opt/Qt/5.15.2/gcc_64/lib/cmake)find_package(Qt5 COMPONENTS Widgets REQUIRED)add_executable(00-Demo main.cpp)
target_link_libraries(00-Demo Qt5::Widgets)

Qt 5.15 以后的版本, 模块库也可以写为 Qt::Widgets, 以便兼容 Qt6

  • main.cpp 的内容:
#include <QApplication>
#include <QWidget>int main(int argc, char *argv[]) {QApplication app(argc, argv);QWidget window;window.resize(320, 240);window.show();return app.exec();  // 主事件循环
}

编译 Qt 项目

进入 Begin/build 目录

$ cd Begin/build/
$ cmake .. && make
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jianghuixin/CLion/Qt5/Begin/build
[ 25%] Automatic MOC and UIC for target 00-Demo
[ 25%] Built target 00-Demo_autogen
[ 50%] Building CXX object CMakeFiles/00-Demo.dir/00-Demo_autogen/mocs_compilation.cpp.o
[ 75%] Building CXX object CMakeFiles/00-Demo.dir/main.cpp.o
[100%] Linking CXX executable 00-Demo
[100%] Built target 00-Demo

在 build 目录生成了 00-Demo 可执行程序, 直接运行

$ ./00-Demo

00-Demo

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

相关文章:

  • ZooKeeper命令及JavaAPI操作
  • 云医疗信息系统源码(云HIS)商业级全套源代码
  • u盘拔掉再插上去文件没了原因|文件恢复方法
  • CorelDRAW2023详解新增七大功能 ,CorelDRAW2023最新版本更新怎么样?
  • LearnOpenGL-光照-4.光照贴图
  • ThreadLocal解析
  • 时间格式表
  • enscape和twinmotion哪个好用?
  • Canvas
  • 旅游预约APP开发具有什么优势和功能
  • Python之函数参数细讲
  • 跑步耳机入耳好还是不入耳好、十大跑步运动耳机品牌排行榜推荐
  • Go语言容器之数组和切片
  • 【ROS2知识】humble下使用插件编程
  • MySQL 主备一致
  • 玩转CodeQLpy之用友GRP-U8漏洞挖掘
  • GMP调度模型总结
  • 蓝桥回文日期题
  • 【2023】某python语言程序设计跟学第三周内容
  • c++11右值引发的概念
  • MySQL 02 :三层结构、备份删除数据库
  • 质量员错题合集
  • 请教大神们,pmp考试和复习有什么攻略诀窍吗?
  • Go语言基础之接口
  • 【Go自学第一节】GoLang 数据类型
  • 学习ForkJoin
  • System has not been booted with systemd as init system (PID 1). Can‘t operate.
  • 使用Endnote自定义参考文献格式
  • jsPlumb Components Crack
  • Java接口