Qt6 QML Book/扩展QML/小结

Summary

小结

The plugin created in thic chapter is a very simple plugin. but it can be re-used and extended by other types for different applications. Using plugins creates a very flexible solution. For example, you can now start the UI by just using the qml. Open the folder where your CityUI project is a start the UI with qml main.qml. The extension is readily available to the QML engine from any project and can be imported anywhere.

本章中创建的插件是一个非常简单的插件。但它可以被其他类型的应用程序重复使用和扩展。使用插件可以创建一个非常灵活的解决方案。例如,现在只需使用qml即可启动UI。打开CityUI项目所在的文件夹,使用qml main.qml启动UI。QML引擎可以从任何项目中随时使用该扩展,并且可以在任何地方导入。

You are encouraged to write your applications in a way so that they work with a qml. This has a tremendous increase in turnaround time for the UI developer and it is also a good habit to keep a clear separation of the logic and the presentation of an application.

我们鼓励您以某种方式编写应用程序,以便它们与qml一起工作。这大大增加了UI开发人员的开发周期,并且保持应用程序的逻辑和表示的清晰分离也是一个好习惯。

The only drawback with using plugins is that the deployment gets more difficult. This becomes more apparent the simpler the application is (as the overhead of creating and deploying the plugin stays the same). You need now to deploy your plugin with your application. If this is a problem for you, you can still use the same FileIO class and register it directly in your main.cpp using qmlRegisterType. The QML code would stay the same.

使用插件的唯一缺点是部署变得更加困难。应用程序越简单,这一点就越明显(因为创建和部署插件的开销保持不变)。现在,您需要在应用程序中部署插件。如果这对您来说是个问题,您仍然可以使用相同的FileIO类,并直接在main.cpp中使用qmlRegisterType注册它。QML代码将保持不变。

In larger projects, you do not use an application as such. You have a simple qml runtime similar to the qml command provided with Qt, and require all native functionality to come as plugins. And your projects are simple pure qml projects using these qml extension plugins. This provides greater flexibility and removes the compilation step for UI changes. After editing a QML file you just need to run the UI. This allows the user interface writers to stay flexible and agile to make all these little changes to push pixels.

在较大的项目中,您不使用这样的应用程序。您有一个简单的qml运行时,类似于Qt提供的qml命令,并且需要所有本地功能作为插件提供。您的项目是使用这些qml扩展插件的简单纯qml项目。这提供了更大的灵活性,并删除了UI更改的编译步骤。编辑QML文件后,只需运行UI。这使得用户界面编写人员能够保持灵活性和敏捷性,以便对像素进行所有这些小的更改。

Plugins provide a nice and clean separation between C++ backend development and QML frontend development. When developing QML plugins always have the QML side in mind and do not hesitate to start with a QML only mockup first to validate your API before you implement it in C++. If an API is written in C++ people often hesitate to change it or not to speak of to rewrite it. Mocking an API in QML provides much more flexibility and less initial investment. When using plugins the switch between a mocked API and the real API is just changing the import path for the qml runtime.

插件在C++后端开发和QML前端开发之间提供了一个干净而干净的分离。当开发QML插件时,始终要考虑QML方面的内容,在C++实现之前先毫不犹豫地从QML开始模型开始验证API。如果API是用C++编写的,人们往往会犹豫是否改变它来重写它。在QML中模拟API提供了更大的灵活性和更少的初始化消耗。使用插件时,模拟API和真实API之间的切换只是更改qml运行时的导入路径。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值