Qt定位的变化

Changes to Qt Positioning

Qt定位的变化

Qt 6 is a result of the conscious effort to make the framework more efficient and easy to use.

Qt 6是有意识地努力使框架更高效、更易于使用的结果。

We try to maintain binary and source compatibility for all the public APIs in each release. But some changes were inevitable in an effort to make Qt a better framework.

我们试图为每个版本中的所有公共API保持二进制和源代码兼容性。但为了使Qt成为一个更好的框架,一些变化是不可避免的。

In this topic we summarize those changes in Qt Positioning, and provide guidance to handle them.

在本主题中,我们总结了Qt定位中的这些变化,并提供了处理这些变化的指导。

Breaking public API changes

打破公共API更改

This section contains information about API changes that break source compatibility.

本节包含有关破坏源代码兼容性的API更改的信息。

Rename QGeoPolygon::path()

重命名QGeoPolygon::path()

The QGeoPolygon::path() and QGeoPolygon::setPath() methods are renamed to QGeoPolygon::perimeter() and QGeoPolygon::setPerimeter() respectively. On the QML side the QGeoPolygon::perimeter property can be used without any changes.

​QGeoPolygon::path()和QGeoPolygon::setPath()方法分别重命名为QGeoPolygon::perimeter()和QGeoPolygon::setPerimeter()。在QML端,可以使用QGeoPolygon::period属性而无需任何更改。

Use QGeoShape for QGeoLocation bounding area

​将QGeoShape用于QGeoLocation边界区域

The QGeoLocation class and its Location QML counterpart are updated to use QGeoShape instead of QGeoRectangle for a bounding area.

​QGeoLocation类及其Location QML对应项被更新为使用QGeoShape而不是QGeoRectangle作为边界区域。

C++

The QGeoLocation::boundingBox() and QGeoLocation::setBoundingBox() are replaced by QGeoLocation::boundingShape() and QGeoLocation::setBoundingShape() respectively. A QGeoShape object is now used as an underlying data storage.

​QGeoLocation::boundingBox()和QGeoLocation::setBoundingBox()​
分别被QGeoLocation::boundingShape()和QGeoLocation::setBoundingShape替换。
​。QGeoShape对象现在用作底层数据存储。

QML

The QGeoLocation::boundingBox property is replaced by QGeoLocation::boundingShape. This property is available since QtPositioning 6.2, so make sure to update the import version in the QML files.

​QGeoLocation::boundingBox属性被QGeoLocation::boundingShape替换。此属性自QtPosition 6.2起可用,因此请确保更新QML文件中的导入版本。

import QtPositioning 6.2

Remove QGeoShape::extendShape()

删除QGeoShape::extendShape()

The QGeoShape::extendShape() method was deprecated in Qt 5.9 and finally removed in Qt 6. Use QGeoRectangle::extendRectangle() and QGeoCircle::extendCircle() if you need this functionality for these classes.

​QGeoShape::extendShape()方法在Qt 5.9中被弃用,最终在Qt 6中被删除。如果需要这些类的此功能,请使用QGeoRectangle::extendRectangle()和QGeoCircle::extendCircle()。

Rename signal error to errorOccurred

将信号错误重命名为errorOccurred

In Qt 5 multiple Qt Positioning classes had the error() signal, which was clashing with the error() method. In Qt 6 we renamed these signals to errorOccurred(). Specifically:

在Qt 5中,多个Qt Positioning类都有error()信号,这与error()方法冲突。在Qt 6中,我们将这些信号重命名为errorCoccurred()。明确地:

Remove update timeout signals

删除更新超时信号

In Qt 5 QGeoPositionInfoSource::updateTimeout() and QGeoSatelliteInfoSource::requestTimeout() signals were used to notify about the cases when the current position or satellite information could not be retrieved within specified timeout. These signals were removed in Qt 6. The errorOccurred() signals with the new error types are used instead. Specifically:

在Qt 5中,QGeoPositionInfoSource::updateTimeout()和QGeoSatelliteInfoSource::requestTimeout()信号用于通知在指定超时内无法检索当前位置或卫星信息的情况。这些信号在Qt 6中被删除了。取而代之的是使用具有新错误类型的errorCoccurred()信号。明确地:

Same changes apply to PositionSource QML object. The PositionSource::updateTimeout() signal is removed. PositionSource::sourceError property with a PositionSource.UpdateTimeoutError is used instead.

​同样的更改也适用于PositionSource QML对象。PositionSource::updateTimeout()信号被删除。PositionSource::sourceError属性带有PositionSource.UpdateTimeoutError取代之。

Redesign NMEA support

重新设计NMEA支持

In Qt 5 we had a serialnmea positioning plugin and a nmeaSource property in PositionSource object.

​在Qt 5中,我们有一个serialnmea定位插件和PositionSource对象中的nmeaSource属性。

The plugin provided access to NMEA streams via serial port, while the QML object was responsible for reading NMEA stream from TCP socket or local file.

该插件通过串行端口提供对NMEA流的访问,而QML对象负责从TCP套接字或本地文件读取NMEA流。

In Qt 6 we joined all these features in the plugin, which is now renamed to nmea. It is now capable of working with all three NMEA data sources: serial port, TCP socket and local file. See plugin description for more details.

​在Qt 6中,我们将所有这些功能都添加到了插件中,该插件现在重命名为nmea。它现在能够处理所有三个NMEA数据源:串行端口、TCP套接字和本地文件。有关更多详细信息,请参阅插件描述。

The nmeaSource property of PositionSource object is now removed.

​PositionSource对象的nmeaSource属性现在已被删除。

Other API changes

API的其他变更

This section contains API improvements that do not break source compatibility. However they might have an impact on the application logic, so it is still useful to know about them.

本节包含不会破坏源代码兼容性的API改进。然而,它们可能会对应用程序逻辑产生影响,因此了解它们仍然很有用。

Reset errors properly

正确重置错误

In Qt 5 the errors for QGeoAreaMonitorSourceQGeoPositionInfoSource and QGeoSatelliteInfoSource classes were never reset. This behavior is not logical, as calling startUpdates()startMonitoring() or requestUpdates() on one of these classes or their subclasses effectively means starting a new work sessions, which means that we should not care about previous errors. Since Qt 6 we reset the error to NoError once one of the aforementioned methods is called.

​在Qt 5中,QGeoAreaMonitorSource、QGeoPositionInfoSource和QGeoSatelliteInfoSource类的错误从未重置。这种行为是不符合逻辑的,因为对其中一个类或其子类调用startUpdates()、startMonitoring()或requestUpdate()实际上意味着启动一个新的工作会话,这意味着我们不应该关心以前的错误。从Qt 6开始,一旦调用上述方法之一,我们就会将错误重置为NoError。

Add QGeoAddress::streetNumber

​添加QGeoAddress::streetNumber

The QGeoAddress class is extended with streetNumber property, which holds the information about street number, building name, or anything else that might be used to distinguish one address from another. Use streetNumber() and setStreetNumber() to access this property from C++ code.

​QGeoAddress类扩展了streetNumber属性,该属性包含有关街道号、建筑名称或可能用于区分一个地址和另一个地址的任何其他信息。使用streetNumber()和setStreetNumber()从C++代码访问此属性。

The QGeoAddress::street now holds only the street name.

​QGeoAddress::street现在只包含街道名称。

Same applies to Address QML counterpart. The Address::street property is now used only for street name, while the Address::streetNumber property is used for other important address details.

​同样适用于地址QML对应方。Address::street属性现在仅用于街道名称,而Address::streetNumber属性用于其他重要的地址详细信息。

Add timeout argument to PositionSource::update()

​向PositionSource::update()添加超时参数

The timeout is specified in milliseconds. If the timeout is zero (the default value), it defaults to a reasonable timeout period as appropriate for the source.

超时以毫秒为单位指定。如果超时为零(默认值),则默认为适合源的合理超时时间。

Refactor QGeoSatelliteInfoQGeoPositionInfo and QGeoAreaMonitorInfo classes

重构类QGeoSatelliteinfo、QGeoPositionInfo和QGeoAreamonitorinfo

These classes now use QExplicitlySharedDataPointer in their implementation. It means that the classes implement copy-on-write. It makes them cheap to copy, so that they can be passed by value.

​这些类现在在其实现中使用QExplicilySharedDataPointer。这意味着这些类实现了写时复制。这使得它们的复制成本低廉,因此可以按值传递。

Another improvement is the addition of support for the efficient move operations.

另一个改进是增加了对高效移动操作的支持。

Changes in Qt Positioning plugin implementation

Qt定位插件实现的变化

This section provides information about the changes in plugin interface.

本节提供有关插件接口更改的信息。

In Qt 5 for we had two versions of plugin interface:

在Qt 5中,我们有两个版本的插件接口:

  • QGeoPositionInfoSourceFactory which provided the basic features.
  • QGeoPositionInfoSourceFactory提供了基本功能。
  • QGeoPositionInfoSourceFactoryV2 which extended the base class with the possibility to provide custom parameters for the created objects.
  • QGeoPositionInfoSourceFactoryV2扩展了基类,可以为创建的对象提供自定义参数。

In Qt 6 we merged these two implementations into one, leaving only the QGeoPositionInfoSourceFactory class. Its methods now allow to pass custom parameters.

​在Qt 6中,我们将这两个实现合并为一个,只留下QGeoPositionInfoSourceFactory类。它的方法现在允许传递自定义参数。

Note: The interface identifier is updated to reflect the major version update. Use "org.qt-project.qt.position.sourcefactory/6.0" in your Qt Positioning plugins.

注意:接口标识符已更新以反映主要版本更新。在qt定位插件中使用“org.qt-project.qt.position.sourcefactory/6.0”。

Here is an example of plugin class declaration:

以下是一个插件类声明的示例:

class MyPlugin : public QObject, public QGeoPositionInfoSourceFactory
{
    Q_OBJECT
    Q_PLUGIN_METADATA(IID "org.qt-project.qt.position.sourcefactory/6.0"
                      FILE "plugin.json")
    Q_INTERFACES(QGeoPositionInfoSourceFactory)

public:
    QGeoPositionInfoSource *positionInfoSource(QObject *parent, const QVariantMap &parameters) override;
    QGeoSatelliteInfoSource *satelliteInfoSource(QObject *parent, const QVariantMap &parameters) override;
    QGeoAreaMonitorSource *areaMonitor(QObject *parent, const QVariantMap &parameters) override;
};

NMEA plugin

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值