QGeoAddress Class

QGeoAddress 类表示QGeoLocation...更多...

头文件: #include <QGeoAddress>
CMake: find_package(Qt6 REQUIRED COMPONENTS Positioning)
target_link_libraries(mytarget PRIVATE Qt6::Positioning)
qmake: QT += positioning

公共函数

QGeoAddress()
QGeoAddress(const QGeoAddress &other)
(since 6.2) QGeoAddress(QGeoAddress &&other)
~QGeoAddress()
QString city() const
void clear()
QString country() const
QString countryCode() const
QString county() const
QString district() const
bool isEmpty() const
bool isTextGenerated() const
QString postalCode() const
void setCity(const QString &city)
void setCountry(const QString &country)
void setCountryCode(const QString &countryCode)
void setCounty(const QString &county)
void setDistrict(const QString &district)
void setPostalCode(const QString &postalCode)
void setState(const QString &state)
void setStreet(const QString &street)
(since 6.2) void setStreetNumber(const QString &streetNumber)
void setText(const QString &text)
QString state() const
QString street() const
(since 6.2) QString streetNumber() const
(since 6.2) void swap(QGeoAddress &other)
QString text() const
(since 6.2) QGeoAddress &operator=(QGeoAddress &other)
QGeoAddress &operator=(const QGeoAddress &address)
size_t qHash(const QGeoAddress &address, size_t seed = 0)
bool operator!=(const QGeoAddress &lhs, const QGeoAddress &rhs)
bool operator==(const QGeoAddress &lhs, const QGeoAddress &rhs)

详细说明

地址的属性已规范化为美国地物名称,并可映射到本地地物级别(例如,州与德国的 "联邦 "相匹配)。

地址包含一个用于显示的text() 和用于访问地址组件的附加属性:

成员函数文档

QGeoAddress::QGeoAddress()

默认构造函数。

QGeoAddress::QGeoAddress(const QGeoAddress &other)

构造other 的副本。

[noexcept, since 6.2] QGeoAddress::QGeoAddress(QGeoAddress &&other)

通过从other 移动构建一个地理地址对象。

注意: 移动后的 QGeoAddress 对象只能被销毁或赋值。调用析构函数或赋值操作符之外的其他函数的效果未定义。

此函数在 Qt 6.2 中引入。

[noexcept] QGeoAddress::~QGeoAddress()

摧毁该地址。

QString QGeoAddress::city() const

返回城市。

另请参见 setCity()。

void QGeoAddress::clear()

清除地址的所有数据字段。

QString QGeoAddress::country() const

返回国家名称。

另请参见 setCountry()。

QString QGeoAddress::countryCode() const

根据 ISO 3166-1 alpha-3 返回国家代码

另请参阅 setCountryCode().

QString QGeoAddress::county() const

返回县。县被认为是国家以下的第二个分支。

另请参阅 setCounty()。

QString QGeoAddress::district() const

返回区。该区被视为城市以下的分区。

另请参见 setDistrict()。

bool QGeoAddress::isEmpty() const

返回该地址是否为空。如果地址的所有字段都为空,则视为空地址。

bool QGeoAddress::isTextGenerated() const

如果QGeoAddress::text() 是由地址元素自动生成的,则返回 true;如果text() 是明确指定的,则返回 false。

另请参阅 text() 和setText()。

QString QGeoAddress::postalCode() const

返回邮政编码。

另请参阅 setPostalCode()。

void QGeoAddress::setCity(const QString &city)

设置city

另请参见 city() 。

void QGeoAddress::setCountry(const QString &country)

设置country 名称。

另请参阅 country().

void QGeoAddress::setCountryCode(const QString &countryCode)

根据 ISO 3166-1 alpha-3 设置countryCode

另请参见 countryCode().

void QGeoAddress::setCounty(const QString &county)

设置county

另请参见 county() 。

void QGeoAddress::setDistrict(const QString &district)

设置district

另请参见 district() 。

void QGeoAddress::setPostalCode(const QString &postalCode)

设置postalCode

另请参见 postalCode() 。

void QGeoAddress::setState(const QString &state)

设置state

另请参见 state() 。

void QGeoAddress::setStreet(const QString &street)

将街道名称设置为street

注意: 在 Qt6 之前,街道名称还可以包含单元号、楼宇名称或其他任何用于区分地址的信息。现在可使用setStreetNumber() 设置该数据。

另请参阅 street() 和setStreetNumber()。

[since 6.2] void QGeoAddress::setStreetNumber(const QString &streetNumber)

将街道编号设置为streetNumber

其中还可能包含单元号、楼宇名称或其他任何可能用于区分不同地址的信息。

注: 在 Qt6 之前,该信息是通过setStreet() 方法设置的。

该函数在 Qt 6.2 中引入。

另请参阅 streetNumber() 和setStreet()。

void QGeoAddress::setText(const QString &text)

如果text 不为空,则明确指定texttext() 返回的字符串。isTextGenerated() 将返回 false。

如果text 为空,则表示text() 应从地址元素中自动生成。isTextGenerated() 将返回 true。

另请参阅 text()。

QString QGeoAddress::state() const

返回州。州被认为是国家以下的第一个分支。

另请参见 setState()。

QString QGeoAddress::street() const

返回街道名称。

注: 在 Qt6 之前,它还可以包含单元号、楼宇名称或其他任何用于区分地址的信息。现在可使用streetNumber() 获取此数据。

另请参阅 setStreet() 和streetNumber()。

[since 6.2] QString QGeoAddress::streetNumber() const

返回街道编号。

其中还可能包含单元号、楼宇名称或其他任何可能用于区分不同地址的信息。

注: 在 Qt6 之前,该信息由street() 方法返回。

该函数在 Qt 6.2 中引入。

另请参阅 setStreetNumber() 和street()。

[noexcept, since 6.2] void QGeoAddress::swap(QGeoAddress &other)

将该地址与other 互换。该操作速度非常快,而且从未出现过故障。

此函数在 Qt 6.2 中引入。

QString QGeoAddress::text() const

以单个格式化字符串的形式返回地址。建议使用该字符串向用户显示地址。它通常采用信封上的地址格式,但不一定总是如此。

地址文本要么是自动生成的,要么是明确指定的。这可以通过检查isTextGenerated 来确定。

如果setText() 收到的是空字符串,那么isTextGenerated() 将被设置为true ,text() 将返回一个根据countryCode() 和地址元素(如街道、城市等)本地格式化的字符串。由于文本字符串是根据地址元素生成的,因此每次调用 text() 时,text()、setStreet()、text() 等一系列调用可能会返回不同的字符串。

如果向setText() 提供了非空字符串,那么isTextGenerated() 将被设置为false ,而 text() 将始终返回明确指定的字符串。调用setStreet() 和setCity() 等其他元素不会影响 text() 的结果字符串。

另请参阅 setText()。

[default, since 6.2] QGeoAddress &QGeoAddress::operator=(QGeoAddress &other)

Move-将other 分配给该地址,并返回对该地址的引用。

注意: 移动后的QGeoAddress 对象只能被销毁或赋值。调用析构函数或赋值操作符之外的其他函数的效果未定义。

此函数在 Qt 6.2 中引入。

QGeoAddress &QGeoAddress::operator=(const QGeoAddress &address)

将给定的address 分配给该地址,并返回对该地址的引用。

相关非会员

[noexcept] size_t qHash(const QGeoAddress &address, size_t seed = 0)

返回address 的哈希值,使用seed 进行计算。

bool operator!=(const QGeoAddress &lhs, const QGeoAddress &rhs)

如果lhs 地址不等于rhs ,则返回true ,否则返回false

bool operator==(const QGeoAddress &lhs, const QGeoAddress &rhs)

如果lhs 地址等于rhs ,则返回true ,否则返回false

© 2025 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.