Qt 6之旅:Felgo的学习和为什么是时候迁移了

The Journey to Qt 6: Felgo’s Learnings and Why it's Time to Migrate

Qt 6之旅:Felgo的学习和为什么是时候迁移了

November 08, 2023 by FELGO | Comments

​2023年11月8日 FELGO|评论

This is a guest blog post by FELGO, an official Qt Technology and Service Partner.

这是官方Qt技术和服务合作伙伴FELGO的博客文章。

Felgo has actively participated in the Qt ecosystem for many years and builds specialized products that support Qt developers in their daily work. This includes the Felgo SDK with 200+ components that simplify cross-platform development and tools such as QML Hot Reload and Felgo Cloud Builds. Ever since the first release of Felgo based on Qt 4, the team has kept a close eye on every new Qt version to adopt the latest changes and bring all new advancements to the Felgo products and Felgo users alike.

Felgo多年来一直积极参与Qt生态系统,并构建专门的产品来支持Qt开发人员的日常工作。这包括Felgo SDK,其中包含200多个简化跨平台开发的组件,以及QML Hot Reload和Felgo Cloud Builds等工具。自Felgo基于Qt 4首次发布以来,团队一直密切关注每一个新的Qt版本,以采用最新的变化,并为Felgo产品和Felgo用户带来所有新的进步。

Felgo-qt6

Due to the nature of Felgo and its products, the team is well-versed in evaluating and incorporating new Qt releases. However, major version updates, like going from Qt 4 to Qt 5 and now to Qt 6, always come with significant changes that require special attention. In addition, Felgo has to ensure that the migration is not only smooth for their own products but also for customers all around the world who rely on the Felgo SDK for building their software.

由于Felgo及其产品的性质,该团队精通评估和整合新的Qt版本。然而,主要的版本更新,如从Qt 4到Qt 5,再到现在的Qt 6,总是伴随着需要特别注意的重大变化。此外,Felgo必须确保迁移不仅对他们自己的产品来说是顺利的,对世界各地依赖Felgo SDK构建软件的客户来说也是如此。

As soon as Qt 6 was released, Felgo started to assess the feasibility and benefits of migration. The team weighed factors such as performance enhancements, developer experience, and the compatibility of existing codebases. This post summarizes the main steps to start using Qt 6 for your products, some challenges Felgo faced during migration, and the benefits of leveraging the new technology.

Qt 6一发布,Felgo就开始评估迁移的可行性和好处。该团队权衡了性能增强、开发人员经验和现有代码库兼容性等因素。这篇文章总结了在您的产品中开始使用Qt6的主要步骤,Felgo在迁移过程中面临的一些挑战,以及利用新技术的好处。

Why it's Time to Migrate

为什么是时候迁移了

While the migration requires some planning and development effort, the advantages of Qt 6 far outmatch the inconveniences during migration. After incorporating Qt 6, Felgo now benefits from many advancements, such as improved performance, enhanced developer tools, and future-proof cross-platform compatibility:

虽然迁移需要一些规划和开发工作,但Qt 6的优势远远超过了迁移过程中的不便。在集成了Qt 6之后,Felgo现在受益于许多进步,如改进的性能、增强的开发工具和经得起未来考验的跨平台兼容性:

  • Qt 6 introduces various optimizations and enhancements that allow applications to run faster and more stable. The revamped rendering architecture and better optimization improve overall application performance, faster startup times, and smoother user interactions.
  • Qt6引入了各种优化和增强功能,使应用程序运行得更快、更稳定。改进后的渲染架构和更好的优化提高了应用程序的整体性能、更快的启动时间和更流畅的用户交互。
  • CMake, as the new default build system, is fast, powerful, and comes with various commands and settings for all kinds of use cases, making advanced build scenarios easier to solve.
  • CMake作为新的默认构建系统,速度快、功能强大,并为各种用例提供了各种命令和设置,使高级构建场景更容易解决。
  • Qt 6's cross-platform compatibility ensures that Felgo's applications can seamlessly run on all the latest operating systems and devices, including Mobile, Desktop, Embedded, and WebAssembly.
  • Qt 6的跨平台兼容性确保了Felgo的应用程序可以在所有最新的操作系统和设备上无缝运行,包括移动、桌面、嵌入式和WebAssembly。

Qt 6 made the right design choices, and with the improved performance, stability, and architecture, it is more powerful than ever. By migrating to Qt 6, developers can position themselves at the forefront of technology, seize new opportunities, and deliver exceptional applications that meet the evolving needs of their users.

Qt6做出了正确的设计选择,性能、稳定性和架构都得到了改进,它比以往任何时候都更强大。通过迁移到Qt 6,开发人员可以将自己定位在技术的前沿,抓住新的机会,并提供满足用户不断发展的需求的卓越应用程序。

Steps for a Successful Migration to Qt  6

成功迁移到Qt 6的步骤

Before migrating a software product to Qt 6, the most important step is thoroughly evaluating the existing code base and the used Qt components and modules. This enables you to identify parts that require refactoring and draft a roadmap for the migration.

在将软件产品迁移到Qt6之前,最重要的步骤是彻底评估现有的代码库以及使用的Qt组件和模块。这使您能够识别需要重构的部分,并为迁移起草路线图。

The migration to Qt 6 involves several changes to ensure a smooth transition while preserving the integrity of existing projects. The following topics must be addressed to align with the Qt 6 framework:

向Qt 6的迁移涉及到几项更改,以确保平稳过渡,同时保持现有项目的完整性。为了与Qt 6框架保持一致,必须解决以下主题:

Project Configuration, Toolchain and IDE Support

项目配置、工具链和IDE支持

CMake is now the preferred build system, as it has many advantages over qmake. CMake speeds up project compilation and simplifies managing QML modules and project resources (QRC). It also enables Qt to significantly increase application performance, e.g., with the improved optimization capabilities of the Qt Quick Compiler.

CMake现在是首选的构建系统,因为它比qmake有很多优势。CMake加快了项目编译并简化了QML模块和项目资源(QRC)的管理。它还使Qt能够显著提高应用程序性能,例如,通过改进Qt Quick编译器的优化功能。

CMake and Qt’s CMake helpers also make it easier to support Qt 5 and Qt 6 in parallel with the same project source code, e.g., with the version-less targets.

CMake和Qt的CMake助手还可以更容易地使用相同的项目源代码并行支持Qt5和Qt6,例如,使用无版本目标。

In addition, the necessary build tools, IDE, and build automation systems need to be updated to match the latest requirements to support building Qt 6 and CMake projects for your target platforms. It is best to tackle these issues early on so you can rely on your CI/CD systems to ensure a solid development process, incorporate quality assurance measures, and benefit from fast deployment cycles during the migration.

此外,需要更新必要的构建工具、IDE和构建自动化系统,以满足最新的需求,从而支持为目标平台构建Qt 6和CMake项目。最好尽早解决这些问题,这样您就可以依靠CI/CD系统来确保坚实的开发过程,纳入质量保证措施,并在迁移过程中受益于快速部署周期。

Changes to C++ and QML APIs

对C++和QML API的更改

The APIs of various Qt components changed. Thus, you must incorporate these changes to build and run your project with Qt 6 successfully. Applying the necessary changes is straightforward for most use cases. See the Changes to Qt Modules in Qt 6 documentation page for more information. Some examples are:

​各种Qt组件的API发生了变化。因此,必须结合这些更改才能成功地使用Qt6构建和运行项目。对于大多数用例来说,应用必要的更改非常简单。有关更多信息,请参阅Qt 6文档页面中的Qt模块更改。例如:

  • Bearer management is removed from Qt Network, and the QNetworkConfiguration and QNetworkConfigurationManager classes no longer exist.
  • 承载管理已从Qt网络中删除,并且QNetworkConfiguration和QNetworkConfigurationManager类不再存在。
  • The QRegExp type is now named QRegularExpression.
  • QRegExp类型现在被命名为QRegularExpression。
  • Qt Multimedia is removing the QML Audio type. You now play audio files with a MediaPlayer and AudioOutput instead.
  • Qt Multimedia正在删除QML Audio类型。现在,您可以使用MediaPlayer和AudioOutput播放音频文件。
  • The QtGraphicalEffects module is not part of Qt 6. Some of the effects are available with the Qt5Compat.GraphicalEffects module. The change in the import statement adds additional complexity if you still need to support Qt 5 and Qt 6 in your code. To work around this, you can either use CMake’s configure_file function or use Qt file selectors to include different QML files per Qt version.
  • Qt图形效果模块不是Qt 6的一部分。Qt5Compat.GraphicalEffects模块提供了一些效果。如果仍然需要在代码中支持Qt5和Qt6,那么import语句中的更改会增加额外的复杂性。要解决此问题,可以使用CMake的configure_file函数,也可以使用Qt文件选择器为每个Qt版本包含不同的QML文件。
  • The Qt Quick Controls 1 module is no longer available, and you have to use Qt Quick Controls 2 or an alternative UI library such as the Felgo SDK instead.
  • Qt Quick Controls 1模块不再可用,必须使用Qt Quick Control 2或其他UI库,如Felgo SDK。

Addressing Functional Differences

解决功能差异

Due to changes in the underlying architecture of Qt 6, various features behave differently, which requires changes in your project source code. Here are some examples:

由于Qt6的底层架构发生了变化,各种功能的表现也有所不同,这需要更改项目源代码。以下是一些示例:

  • Qt 6 introduces a new rendering hardware abstraction layer, which affects features that rely on native rendering. In Felgo’s case, some features require the use of OpenGL, which can be solved by configuring the graphics API that Qt should use, e.g., with setting: QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
  • Qt6引入了一个新的渲染硬件抽象层,它影响了依赖于本地渲染的特性。在Felgo的情况下,一些功能需要使用OpenGL,这可以通过配置Qt应该使用的图形API来解决,例如,设置:QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);

  • High-dpi mode for rendering density-independent user interfaces is enabled by default now. The Qt::AA_EnableHighDpiScaling setting is no longer required, and it is not advised to disable it unless for testing purposes.
  • 用于渲染密度无关用户界面的高dpi模式现在默认启用。Qt::AA_EnableHighDpiScaling设置不再需要,除非出于测试目的,否则不建议禁用它。

  • The window menu bar of Qt Quick applications is now a custom-rendered menu. This means that the menu style is consistent across platforms and does not automatically adapt to native menu solutions of the respective platform. When using C++ widgets, there’s no change, and the platform-native menu is used.
  • Qt Quick应用程序的窗口菜单栏现在是一个自定义渲染菜单。这意味着菜单样式在各个平台上是一致的,并且不会自动适应相应平台的本地菜单解决方案。当使用C++ widget时,没有任何更改,而是使用平台本机菜单。

Syntax Changes to Qt Quick and QML

Qt-Quick和QML的语法变化

Qt Quick code no longer requires a specific version for module imports. Also, signal handlers without defined parameters are deprecated and should be replaced. This example uses a version-less import and shows how to access the mouse event object of the MouseArea::clicked signal:

Qt Quick代码不再需要用于模块导入的特定版本。此外,不推荐使用没有定义参数的信号处理程序,应予以替换。此示例使用无版本导入,并显示如何访问MouseArea::clicked信号的鼠标事件对象:

import QtQuick

 

MouseArea {

  acceptedButtons: Qt.LeftButton | Qt.RightButton

  onClicked: (mouse) => {

               if (mouse.button === Qt.LeftButton) {

                 console.log("left clicked");
               }

               else {

                 console.log("right clicked");

             }

      }

}


If you still need to support Qt 5 and Qt 6 in parallel, you can keep your “2.x” import versions in code.

如果仍然需要并行支持Qt5和Qt6,可以在代码中保留“2.x”导入版本。

The Felgo Approach to Qt  6 Migration

Qt6迁移的Felgo方法

The Felgo SDK takes advantage of many different Qt modules and features. It was not feasible to immediately switch to Qt 6 as the primary target version when 6.0 was released.

Felgo SDK利用了许多不同的Qt模块和功能。在6.0发布时,立即切换到Qt 6作为主要目标版本是不可行的。

Instead, Felgo decided to take a step-by-step approach to the migration, first creating a base version with a minimum feature set of the Felgo SDK. With each new Qt release, Felgo iterated the version until the SDK supported all of the core functionality and modules, which was the Qt 6.2 release at the end of 2021.

相反,Felgo决定采取循序渐进的方法进行迁移,首先创建一个带有Felgo SDK最低功能集的基础版本。在每一个新的Qt版本中,Felgo都会迭代该版本,直到SDK支持所有核心功能和模块,即2021年底的Qt 6.2版本。

Felgo-qtversions

To add all the remaining Felgo features, the team then continued this process until the Qt 6.4.1 release, which was the final building block for the first Felgo 4 release.

​为了添加Felgo的所有剩余功能,团队继续这个过程,直到Qt 6.4.1发布,这是Felgo 4第一个发布的最后一个构建块。

In addition, it was clear that tools such as Felgo QML Hot Reload and Felgo Cloud Builds are helpful during the migration process. Thus, the team first focused on preparing these tools for Qt 6. This decision made future work on the Felgo SDK components and collaboration within the team much more straightforward and allowed us to move fast.

此外,很明显,Felgo QML Hot Reload和Felgo Cloud Builds等工具在迁移过程中很有帮助。因此,团队首先专注于为Qt 6准备这些工具。这一决定使Felgo SDK组件的未来工作和团队内部的合作更加简单,并使我们能够快速前进。

felgo-overview

Soon after the Felgo tools and the core feature set were fully migrated, Felgo started to meticulously test every byte of the solution internally and with selected customers.

Felgo工具和核心功能集完全迁移后不久,Felgo就开始在内部和选定的客户中仔细测试解决方案的每一个字节。

Leveraging Felgo Tools: QML Hot Reload 

利用Felgo工具:QML热重新加载

The Felgo SDK and tools have a strong focus on Qt Quick, and QML Hot Reload proved to be an invaluable asset for Felgo during the migration to Qt 6. It allows developers to make real-time changes to the QML code and see the updates instantly reflected in the running application without losing the current state. This eliminates the need for time-consuming recompilation and restarts. 

Felgo SDK和工具非常关注Qt Quick,QML Hot Reload在迁移到Qt 6期间被证明是Felgo的宝贵资产。它允许开发人员对QML代码进行实时更改,并在不丢失当前状态的情况下查看在运行的应用程序中即时反映的更新。这消除了耗时的重新编译和重新启动的需要。

https://youtu.be/KaA3gxDj8uw

The boost in productivity allowed Felgo to iterate rapidly on their QML APIs and experiment with different design choices. This made refactoring and migrating Felgo SDK controls and UI components much more straightforward.

生产力的提高使Felgo能够在QML API上快速迭代,并尝试不同的设计选择。这使得重构和迁移FelgoSDK控件和UI组件变得更加简单。

It also facilitated ongoing improvements and fine-tuning as the team embraced the capabilities of Qt 6. The latest version of QML Hot Reload for Qt 6 additionally gained new features such as an error screen and the ability to roll back changes and errors for a seamless reload experience.

随着团队接受Qt 6的能力,它也促进了持续的改进和微调。Qt 6的最新版本QML热重新加载还获得了新功能,如错误屏幕和回滚更改和错误的能力,以获得无缝的重新加载体验。

Streamlined Development with Felgo Cloud Builds CI/CD

使用Felgo Cloud简化开发构建CI/CD

In addition to QML Hot Reload, Felgo also harnessed the power of Cloud Builds as a convenient and efficient solution for building and deploying Qt 6 applications.

除了QML Hot Reload,Felgo还利用Cloud Builds的强大功能,将其作为构建和部署Qt 6应用程序的方便高效的解决方案。

https://youtu.be/MobDxMRC1vk

With Cloud Builds, Felgo developers can leverage a scalable cloud infrastructure to compile Qt projects. This accelerated the migration process and enabled the integration of Qt 6 into many different customer projects.

通过云构建,Felgo开发人员可以利用可扩展的云基础设施来编译Qt项目。这加快了迁移过程,并使Qt 6能够集成到许多不同的客户项目中。

Felgo-cloudbuilds2

With the ability to build multiple platforms simultaneously, Felgo Cloud Builds allowed the team to ensure fast development cycles and deliver and test efficiently.

Felgo Cloud Builds能够同时构建多个平台,使团队能够确保快速的开发周期,并高效地交付和测试。

Felgo: Your Qt 6 Migration Partner

Felgo:Qt 6迁移合作伙伴

300x150_felgo logo

As we have discussed, Qt 6 is a big step forward in quality and ease of use, and most projects will benefit from migrating from earlier Qt versions. Felgo, with its combination of tools and Qt experts, is ideally suited for helping you enjoy the benefits of Qt 6 without delay.

正如我们所讨论的,Qt6在质量和易用性方面向前迈出了一大步,大多数项目都将从早期的Qt版本迁移中受益。Felgo结合了工具和Qt专家,非常适合帮助您毫不拖延地享受Qt 6的好处。

Felgo's powerful tools, such as QML Hot Reload and Cloud Builds, streamlined development and accelerated the adoption of Qt 6. The migration also lays the foundation for future projects, ensuring high-quality applications and efficient utilization of Qt 6's capabilities.

Felgo强大的工具,如QML Hot Reload和Cloud Builds,简化了开发并加速了Qt 6的采用。迁移还为未来的项目奠定了基础,确保了高质量的应用程序和Qt6功能的高效利用。

Felgo is ready to help you migrate to Qt 6 with training, consulting, tools, and experts. Whether you are looking for migration knowledge or want to hand off your migration to free up your development time, Felgo is ready to help you with your Qt 6 journey!

Felgo随时准备通过培训、咨询、工具和专家帮助您迁移到Qt 6。无论您是在寻找迁移知识,还是想放弃迁移以腾出开发时间,Felgo都随时准备帮助您完成Qt 6之旅!

If you are attending the upcoming Qt World Summit 2023 in Berlin, don’t forget to stop by the Felgo booth to learn more about their unique products for efficient development. The Felgo team welcomes you with many exciting demos and insights.

如果你正在参加即将在柏林举行的2023年Qt世界峰会,别忘了去Felgo展位了解更多关于他们独特产品的信息,以实现高效开发。Felgo团队以许多激动人心的演示和见解欢迎您。

------

About Felgo
关于Felgo

Felgo has been a Qt Technology Partner since 2014, with the goal of helping Qt developers be more productive.

Felgo自2014年以来一直是Qt技术合作伙伴,其目标是帮助Qt开发人员提高生产力。

Felgo is also a Qt Service Partner for development servicesQt training, and workshops. To learn more about Felgo, visit their website or booth at the Qt World Summit 2023 in Berlin on November 28-29, 2023.

​Felgo还是Qt服务合作伙伴,负责开发服务、Qt培训和研讨会。要了解更多关于Felgo的信息,请访问他们的网站或2023年11月28-29日在柏林举行的2023年Qt世界峰会的展位。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值