Qt Widgets、QML、Qt Quick 的区别

作者: 一去、二三里
个人微信号: iwaleon
微信公众号: 高效程序员

在接触 Qt 之后,很多人难免会有一些疑惑:

  • Q1:QML 和 Qt Quick 之间有什么区别?
  • Q2:QtQuick 1.x 和 QtQuick 2.x 之间有什么区别?
  • Q3:为什么要引入 QML/Qt Quick?
  • Q4:Qt Widgets 和 QML/Qt Quick 哪个更好?

QML VS Qt Quick

从概念上区分

为了更精确地对两者进行说明,来看助手的描述:

QML is a user interface specification and programming language.

QML 是一种用户界面规范和标记语言,允许开发人员/设计师创建高性能的、动画流畅的和视觉吸引人的应用程序。

有点儿意思,文档对 QML 的定义主要分为两点:

  1. 用户界面规范:QML 提供了一种高度可读、声明性、类似 JSON 的语法,支持与动态属性绑定相结合的命令式 JavaScript 表达式;
  2. 标记语言:像 C++ 一样,QML 是一种语言,文件格式以 .qml 结尾。

Qt Quick is the standard library of types and functionality for QML.

Qt Quick 是 QML 类型和功能的标准库,包括:视觉类型、交互式类型、动画、模型和视图、粒子效果和着色效果等。

Qt Quick 使用 QML 作为声明语言,来设计以用户界面为中心的应用程序。严格来讲,Qt Quick 是一个用于 QML 的工具包,允许以 QML 语言来开发图形界面。当然,还有其他的工具包用于 QML:

从模块上区分

QML 由 Qt QML 模块提供,QtQuick QML 库由 Qt Quick 模块提供。

  • Qt QML 模块:为 QML 应用程序提供了语言和引擎基础结构。
  • Qt Quick 模块:提供了许多可视化组件、模型视图支持、动画框架以及用于构建用户界面的更多功能。

QtQuick 1.x VS QtQuick 2.x

QtQuick 主要包括:QtQuick 1.x 和 QtQuick 2.x,它们之间的区别主要涉及以下内容:

  • 全新的 Qt 版本

    • QtQuick 1.x 基于 Qt4.x
    • QtQuick 2.x 随 Qt5.0 一起引入
  • 全新的绘图系统

    • QtQuick 1.x 使用 QGraphicsView/QPainter API 来绘制场景
    • QtQuick 2.x 基于 Scene Graph,一个 OpenGL(ES)2.0 抽象层,对绘图进行了高度优化,效率更高。
  • 全新的 QML 引擎

    • Qt 4.x 中,QML 引擎基于JSC(JavaScriptCore - Webkit 的 JS 引擎)。
    • Qt 5.0 中引入 V8(Google 的开源高性能 JavaScript 引擎,用 C++ 编写,用于 Chromium、Node.js 和多个其他嵌入应用程序)。
    • Qt 5.2 中引入了 V4 JS 引擎,针对 QML 用例进行了优化,并且可以选择关闭 JIT(Just-In-Time)编译,以符合 iOS 和 WinRT 平台的限制。个头更小、反应更快、扩展性也非常好。
    • 从 Qt 5.5 开始,加入了一个新模块 QtQuick3D,它提供使用 QML 语言创建 3D 应用程序/游戏的能力,其使用的是一个被命名为 FrameGraph 的新引擎,而非 Scene Graph(因为太 2D/2.4D)。
  • 模块、属性和方法、类型和 API、C++ 代码(QtDeclarative 被移除了,替代的它是 Qt QML 和 Qt Quick 模块)、QML 插件的更改。

为什么要引入 QML/Qt Quick?

在我看来,主要归结为以下几点:

  • 战略性发展

Qt 想用 QML/Qt Quick 一统天下(桌面 + 移动端)。梦想还是要有的,万一实现了呢?

众所周知,Qt 为跨平台而生,而 QML/Qt Quick 作为 Qt 新生力量,完完全全继承了 Qt 包罗万象的特点,它的诞生为 Qt 进军移动领域迈出了历史性的一步。

随着 Qt 的不断迭代,QML/Qt Quick 也可用于开发传统的桌面程序,而且效率越来越高,这样一来,便可以用 QML/Qt Quick 做任何你想做的事情。

QML/Qt Quick 作为 Qt 的绝对核心,特别是对于界面要求较高的开发者来说,其作用更为重要。

  • 开发效率的提升

传统上的 native UI 开发普遍使用 C++、C#、Objective-C 等语言。但近年来,本地应用使用 HTML5 + JS 也成为了一种趋势。一方面硬件资源越来越丰富,另一方面 Web 技术让 JS 的解析速度更快。

除此之外,其中一部分功劳要归功于 Google,由于开源了其 NB 的 JS 引擎,Node.js 加上一个前端框架也可以开发本地应用了。例如:Electron - 构建跨平台的桌面应用程序。

QML/Qt Quick 和 Node.js 类似,也提供了一系列 JS 和 C++ 交互的接口,便于 JS 和 C++ 通信。

  • UI 与逻辑分离

尽管对于大多数情况而言,在编写应用程序时只需 QML 和 JavaScript,但在有些情况下需要计算密集型任务(例如:复杂图像处理、物理引擎),并且将需要处理器竭力提供所有可用性能。

在这些情况下,QML 应用开发适合使用 C++ 来进行扩展,以便在后台执行资源密集型任务,而界面设计和一些简单逻辑(例如:按钮变色、换肤、变形等)都可以在 JS 中完成。这样避免了传统应用开发前端设计和后台逻辑混合的情况,让界面设计者专心设计界面成为了可能。

由于 QML 是在 Qt 上构建的,因此其继承了 Qt 框架中的大部分功能,尤其是信号槽机制以及元对象系统。使用 C++ 创建的数据可从 QML 直接访问,而 QML 对象也可从 C++ 代码进行访问。

Qt Widgets VS QML/Qt Quick

Qt 4.7 发布时,引入了 QML,用于移动开发,其全面支持触摸操作、流畅的动画效果等。但在 Qt 5 之后,QML 已经不再局限于移动开发,也可用于开发传统的桌面程序。

很长时间里,我都在使用 Qt Widgets。当第一次尝试 QML 时,发现它太原始。但随着 Qt 5 的持续更新,QML 已经大大改善 - 添加了更多的功能、更好的性能以及更多的平台支持。话虽如此,但 QML/Qt Quick 仍在发展,随着版本的更新,也会变得越来越成熟。

  • 相比之下,Qt Widgets 更老、更成熟,而 QML/Qt Quick 则更新、更现代。
  • 无论如何,Qt Widgets 和 QML/Qt Quick 都可以在多个平台上使用(Windows、Linux、MacOS…)。

对于传统的桌面程序来说,优先考虑使用 Qt Widgets,若要开发更现代的 UI 与高级应用,建议使用 Qt5.x + QML 2.x + QtQuick 2.x。

对于移动端开发来说,建议使用 QML,协同 JavaScript,简单快捷、渲染效果更佳、界面更炫酷。不建议使用 Qt Widgets,其显示效果、适应性都不好。

  • 69
    点赞
  • 132
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 7
    评论
Building on: linux-g++ (x86_64, CPU features: mmx sse sse2) Building for: linux-aarch64-gnu-g++ (arm64, CPU features: neon) Target compiler: gcc 6.3.1 Configuration: cross_compile use_gold_linker compile_examples enable_new_dtags largefile neon precompile_header shared rpath release c++11 c++14 concurrent dbus reduce_exports stl Build options: Mode ................................... release Optimize release build for size ........ no Building shared libraries .............. yes Using C standard ....................... C11 Using C++ standard ..................... C++14 Using ccache ........................... no Using gold linker ...................... yes Using new DTAGS ........................ yes Using precompiled headers .............. yes Using LTCG ............................. no Target compiler supports: NEON ................................. yes Build parts ............................ libs Qt modules and options: Qt Concurrent .......................... yes Qt D-Bus ............................... yes Qt D-Bus directly linked to libdbus .... no Qt Gui ................................. yes Qt Network ............................. yes Qt Sql ................................. yes Qt Testlib ............................. yes Qt Widgets ............................. yes Qt Xml ................................. yes Support enabled for: Using pkg-config ....................... yes udev ................................... no Using system zlib ...................... yes Qt Core: DoubleConversion ....................... yes Using system DoubleConversion ........ no GLib ................................... no iconv .................................. yes ICU .................................... no Tracing backend ........................ Logging backends: journald ............................. no syslog ............................... no slog2 ................................ no Using system PCRE2 ..................... no Qt Network: getifaddrs() ........................... yes IPv6 ifname ............................ yes libproxy ............................... no Linux AF_NETLINK ....................... yes OpenSSL ................................ yes Qt directly linked to OpenSSL ........ no OpenSSL 1.1 ............................ no DTLS ................................... yes SCTP ................................... no Use system proxies ..................... yes Qt Gui: Accessibility .......................... yes FreeType ............................... yes Using system FreeType ................ no HarfBuzz ............................... yes Using system HarfBuzz ................ no Fontconfig ............................. no Image formats: GIF .................................. yes ICO .................................. yes JPEG ................................. yes Using system libjpeg ............... yes PNG .................................. yes Using system libpng ................ no EGL .................................... no OpenVG ................................. no OpenGL: Desktop OpenGL ....................... no OpenGL ES 2.0 ........................ no OpenGL ES 3.0 ........................ no OpenGL ES 3.1 ........................ no OpenGL ES 3.2 ........................ no Vulkan ................................. no Session Management ..................... yes Features used by QPA backends: evdev .................................. yes libinput ............................... no INTEGRITY HID .......................... no mtdev .................................. no tslib .................................. no xkbcommon .............................. no X11 specific: XLib ................................. no EGL on X11 ........................... no QPA backends: DirectFB ............................... no EGLFS .................................. no LinuxFB ................................ yes VNC .................................... yes Mir client ............................. no Qt Sql: SQL item models ........................ yes Qt Widgets: GTK+ ................................... no Styles ................................. Fusion Windows Qt PrintSupport: CUPS ................................... no Qt Sql Drivers: DB2 (IBM) .............................. no InterBase .............................. no MySql .................................. no OCI (Oracle) ........................... no ODBC ................................... no PostgreSQL ............................. no SQLite2 ................................ no SQLite ................................. yes Using system provided SQLite ......... no TDS (Sybase) ........................... no Qt Testlib: Tester for item models ................. yes Qt SerialBus: Socket CAN ............................. yes Socket CAN FD .......................... yes Qt QML: QML network support .................... yes QML debugging and profiling support .... yes QML sequence object .................... yes QML list model ......................... yes QML XML http request ................... yes QML Locale ............................. yes QML delegate model ..................... yes Qt Quick: Direct3D 12 ............................ no AnimatedImage item ..................... yes Canvas item ............................ yes Support for Qt Quick Designer .......... yes Flipable item .......................... yes GridView item .......................... yes ListView item .......................... yes TableView item ......................... yes Path support ........................... yes PathView item .......................... yes Positioner items ....................... yes Repeater item .......................... yes ShaderEffect item ...................... yes Sprite item ............................ yes Qt Scxml: ECMAScript data model for QtScxml ...... yes Qt Gamepad: SDL2 ................................... no Qt 3D: Assimp ................................. yes System Assimp .......................... no Output Qt3D Job traces ................. no Output Qt3D GL traces .................. no Use SSE2 instructions .................. no Use AVX2 instructions .................. no Aspects: Render aspect ........................ yes Input aspect ......................... yes Logic aspect ......................... yes Animation aspect ..................... yes Extras aspect ........................ yes Qt 3D Renderers: OpenGL Renderer ........................ yes Qt 3D GeometryLoaders: Autodesk FBX ........................... no Qt Wayland Client ........................ no Qt Wayland Compositor .................... no Qt Bluetooth: BlueZ .................................. no BlueZ Low Energy ....................... no Linux Crypto API ....................... no WinRT Bluetooth API (desktop & UWP) .... no Qt Sensors: sensorfw ............................... no Qt Quick Controls 2: Styles ................................. Default Fusion Imagine Material Universal Qt Quick Templates 2: Hover support .......................... yes Multi-touch support .................... yes Qt Positioning: Gypsy GPS Daemon ....................... no WinRT Geolocation API .................. no Qt Location: Qt.labs.location experimental QML plugin . yes Geoservice plugins: OpenStreetMap ........................ yes HERE ................................. yes Esri ................................. yes Mapbox ............................... yes MapboxGL ............................. no Itemsoverlay ......................... yes QtXmlPatterns: XML schema support ..................... yes Qt Multimedia: ALSA ................................... no GStreamer 1.0 .......................... no GStreamer 0.10 ......................... no Video for Linux ........................ yes OpenAL ................................. no PulseAudio ............................. no Resource Policy (libresourceqt5) ....... no Windows Audio Services ................. no DirectShow ............................. no Windows Media Foundation ............... no Qt Tools: QDoc ................................... no Qt WebEngine: Embedded build ......................... yes Pepper Plugins ......................... no Printing and PDF ....................... no Proprietary Codecs ..................... no Spellchecker ........................... yes Native Spellchecker .................... no WebRTC ................................. no Use System Ninja ....................... no Geolocation ............................ yes WebChannel support ..................... yes Use v8 snapshot ........................ yes Kerberos Authentication ................ no Building v8 snapshot supported ......... yes Use ALSA ............................... no Use PulseAudio ......................... no Optional system libraries used: re2 .................................. no icu .................................. no libwebp, libwebpmux and libwebpdemux . no opus ................................. no ffmpeg ............................... no libvpx ............................... no snappy ............................... no glib ................................. no zlib ................................. yes minizip .............................. no libevent ............................. no jsoncpp .............................. no protobuf ............................. no libxml2 and libxslt .................. no lcms2 ................................ no png .................................. no JPEG ................................. no harfbuzz ............................. no freetype ............................. no x11 .................................. no Required system libraries: fontconfig ........................... no dbus ................................. no nss .................................. no khr .................................. no glibc ................................ yes Required system libraries for qpa-xcb: libdrm ............................... no xcomposite ........................... no xcursor .............................. no xi ................................... no xrandr ............................... no xtst ................................. no Note: Also available for Linux: linux-clang linux-icc
A complete guide to designing and building fun games with Qt and Qt Quick 2 using associated toolsets About This Book Learn to create simple 2D to complex 3D graphics and games using all possible tools and widgets available for game development in Qt Understand technologies such as QML, Qt Quick, OpenGL, and Qt Creator, and learn the best practices to use them to design games Learn Qt with the help of many sample games introduced step-by-step in each chapter Who This Book Is For If you want to create great graphical user interfaces and astonishing games with Qt, this book is ideal for you. Any previous knowledge of Qt is not required, however knowledge of C++ is mandatory. What You Will Learn Install Qt on your system Understand the basic concepts of every Qt game and application Develop 2D object-oriented graphics using Qt Graphics View Build multiplayer games or add a chat function to your games with Qt's Network module Script your game with Qt Script Program resolution-independent and fluid UI using QML and Qt Quick Control your game flow as per the sensors of a mobile device See how to test and debug your game easily with Qt Creator and Qt Test In Detail Qt is the leading cross-platform toolkit for all significant desktop, mobile, and embedded platforms and is becoming more popular by the day, especially on mobile and embedded devices. Despite its simplicity, it's a powerful tool that perfectly fits game developers' needs. Using Qt and Qt Quick, it is easy to build fun games or shiny user interfaces. You only need to create your game once and deploy it on all major platforms like iOS, Android, and WinRT without changing a single source file. The book begins with a brief introduction to creating an application and preparing a working environment for both desktop and mobile platforms. It then dives deeper into the basics of creating graphical interfaces and Qt core concepts of data processing and display before you try creating a game. As you progress through the chapters, you'll learn to enrich your games by implementing network connectivity and employing scripting. We then delve into Qt Quick, OpenGL, and various other tools to add game logic, design animation, add game physics, and build astonishing UI for the games. Towards the final chapters, you'll learn to exploit mobile device features such as accelerators and sensors to build engaging user experiences. If you are planning to learn about Qt and its associated toolsets to build apps and games, this book is a must have. Style and approach This is an easy-to-follow, example-based, comprehensive introduction to all the major features in Qt. The content of each chapter is explained and organized around one or multiple simple game examples to learn Qt in a fun way. Table of Contents Chapter 1: Introduction to Qt Chapter 2: Installation Chapter 3: Qt GUI Programming Chapter 4: Qt Core Essentials Chapter 5: Graphics with Qt Chapter 6: Graphics View Chapter 7: Networking Chapter 8: Scripting Chapter 9: Qt Quick Basics Chapter 10: Qt Quick Appendix: Pop Quiz Answers
Qt QuickQt Widgets是Qt框架中用于创建用户界面的两种不同的技术。Qt Widgets是传统的基于C++的用户界面框架,而Qt Quick是基于QML的现代化UI框架。 Qt Widgets主要通过使用C++代码来创建和管理用户界面元素,它提供了丰富的预定义的UI组件和功能,可以通过编写C++代码来实现复杂的界面逻辑和交互。Qt Widgets适合开发传统的桌面应用程序和较为复杂的界面。 而Qt Quick使用QMLQt Meta-Object Language)语言来描述用户界面。QML是一种声明性语言,使用类似于JavaScript的语法,可以通过编写简洁的代码来创建精美的界面。Qt Quick还提供了一套丰富的可重用的UI组件,可以用于快速构建现代化的界面。Qt Quick适合开发移动应用程序和涉及动画和视觉效果的界面。 引入Qt QuickQt Widgets的原因是为了满足现代化UI界面的需求。Qt Quick可以提供更炫酷和复杂的界面效果,同时也能提高开发效率和代码可维护性。而Qt Widgets仍然有其优势和适用场景,因此Qt Widgets和Qt Quick可以根据实际需求灵活地结合使用。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [简单介绍Qt QuickQML以及Qt Widgets之间的区别与联系](https://blog.csdn.net/Jacksqh/article/details/130703212)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一去丶二三里

有收获,再打赏!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值