Qt6 QML Book/Qt C++/Qt与C++

Qt and C++

Qt与C++

Qt is a C++ toolkit with an extension for QML and Javascript. There exist many language bindings for Qt, but as Qt itself is developed in C++. The spirit of C++ can be found throughout the classes. In this section, we will look at Qt from a C++ perspective to build a better understanding of how to extend QML with native plugins developed using C++. Through C++, it is possible to extend and control the execution environment provided to QML.

Qt是一个C++工具包,它有QML和JavaScript的扩展。Qt有很多语言绑定,但是Qt本身是在C++中开发的。C++的思想可以贯穿于整个类。在本节中,我们将从C++的角度来研究Qt,以更好地理解如何使用C++开发的本地插件扩展QML。通过C++,可以扩展和控制提供给QML的执行环境。

This chapter will, just as Qt, require the reader to have some basic knowledge of C++. Qt does not rely on advanced C++ features and I generally consider the Qt style of C++ to be very readable, so do not worry if you feel that your C++ knowledge is shaky.

本章将像Qt一样要求读者掌握C++的一些基本知识。Qt不依赖于高级C++特性,我一般认为C++的Qt风格非常可读,所以如果你觉得C++知识不牢靠,不要担心。

Qt C++

Approaching Qt from a C++ direction, you will find that Qt enriches C++ with a number of modern language features enabled through making introspection data available. This is made possible through the use of the QObject base class. Introspection data, or metadata, maintains information of the classes at run-time, something that ordinary C++ does not do. This makes it possible to dynamically probe objects for information about such details as their properties and available methods.

从C++方向接近Qt,您会发现Qt通过使内省数据变得可用而丰富了C++的一些现代语言特征。这是通过使用QObject基类实现的。自省数据或元数据维护运行时类的信息,这是普通C++不做的事情。这使得动态探测对象的属性和可用方法等细节信息成为可能。

Qt uses this meta information to enable a very loosely bound callback concept using signals and slots. Each signal can be connected to any number of slots or even other signals. When a signal is emitted from an object instance, the connected slots are invoked. As the signal emitting object does not need to know anything about the object owning the slot and vice versa, this mechanism is used to create very reusable components with very few inter-component dependencies.

Qt使用这个元信息来启用一个非常松散的回调概念,使用信号和插槽。每个信号都可以连接到任意数量的插槽,甚至可以连接到其他信号。当对象实例发出信号时,将调用连接的插槽。由于发出信号的对象不需要知道拥有插槽的对象的任何信息,反之亦然,因此该机制用于创建可重用的组件,组件之间的依赖关系非常少。

Qt for Python

The introspection features are also used to create dynamic language bindings, making it possible to expose a C++ object instance to QML and making C++ functions callable from Javascript. Other bindings for Qt C++ exist and besides the standard Javascript binding, the official one is the Python binding called PySide6.

​内省功能也用于创建动态语言绑定,使得将C++对象实例暴露给QML,并使C++函数从JavaScript调用成为可能。Qt C++的其他绑定存在,除了标准JavaScript绑定之外,官方的Javascript绑定是python绑定席名为PySide6。

Cross Platform

跨平台

In addition to this central concept, Qt makes it possible to develop cross-platform applications using C++. Qt C++ provides a platform abstraction on the different operating systems, which allows the developer to concentrate on the task at hand and not the details of how you open a file on different operating systems. This means you can re-compile the same source code for Windows, OS X, and Linux and Qt takes care of the different OS ways of handling certain things. The end result is natively built applications with the look and feel of the target platform. As the mobile is the new desktop, newer Qt versions can also target a number of mobile platforms using the same source code, e.g. iOS, Android, Jolla, BlackBerry, Ubuntu Phone, Tizen.

除了这个中心概念,Qt使得可以使用C++开发跨平台的应用程序。Qt C++提供了对不同操作系统的平台抽象,这允许开发人员集中精力处理手头的任务,而不是如何在不同的操作系统上打开文件的细节。这意味着您可以为Windows、OS X和Linux重新编译相同的源代码,Qt负责处理某些事情的不同操作系统方式。最终的结果是使用目标平台的外观和感觉,以本机方式构建应用程序。由于手机是新的桌面系统,较新的Qt版本也可以针对使用相同源代码的多个移动平台,例如iOS、Android、Jolla、BlackBerry、Ubuntu Phone和Tizen。

When it comes to re-using, not only can source code be re-used but developer skills are also reusable. A team knowing Qt can reach out to far more platforms then a team just focusing on a single platform specific technology and as Qt is so flexible the team can create different system components using the same technology.

说到重用,不仅源代码可以重用,开发人员的技能也可以重用。了解Qt的团队可以接触到更多的平台,而不仅仅是专注于单一平台特定技术的团队,由于Qt非常灵活,团队可以使用相同的技术创建不同的系统组件。

For all platform, Qt offers a set of basic types, e.g. strings with full Unicode support, lists, vectors, buffers. It also provides a common abstraction to the target platform’s main loop, and cross-platform threading and networking support. The general philosophy is that for an application developer Qt comes with all required functionality included. For domain-specific tasks such as to interface to your native libraries, Qt comes with several helper classes to make this easier.

对于所有平台,Qt都提供了一组基本类型,例如完全支持Unicode的字符串、列表、向量和缓冲区。它还提供了对目标平台主循环的通用抽象,以及跨平台线程和网络支持。一般的理念是,对于应用程序开发人员来说,Qt包含了所有必需的功能。对于特定于域的任务,例如与本地库的接口,Qt附带了几个帮助器类,使之更容易实现。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值