本页内容

QMetaObject::Connection Class

class QMetaObject::Connection

公共函数

Connection()
Connection(const QMetaObject::Connection &other)
Connection(QMetaObject::Connection &&o)
~Connection()
void swap(QMetaObject::Connection &other)
operator bool() const
QMetaObject::Connection &operator=(QMetaObject::Connection &&other)
QMetaObject::Connection &operator=(const QMetaObject::Connection &other)

详细说明

表示信号-插槽(或信号-函子)连接的句柄。

它可用于检查连接是否有效,并使用 `QObject::disconnect()` 断开连接。对于没有上下文对象的信号-函子连接,这是有选择地断开该连接的唯一方法。

由于 Connection 只是一个句柄,因此当 Connection 被销毁或重新分配时,底层的信号-插槽连接不会受到影响。

成员函数文档

[noexcept] Connection::Connection()

创建一个 Connection 实例。

Connection::Connection(const QMetaObject::Connection &other)

创建other 连接句柄的副本

[noexcept] Connection::Connection(QMetaObject::Connection &&o)

通过Move构造一个Connection实例,使其指向与o 所指向的同一对象。

[noexcept] Connection::~Connection()

QMetaObject::Connection 的析构函数。

[noexcept] void Connection::swap(QMetaObject::Connection &other)

将此 Connection 实例与other 互换。此操作速度极快,且绝不会失败。

Connection::operator bool() const

如果连接有效,则返回true 。

若对 `QObject::connect ` 的调用成功,则连接有效;若 `QObject::connect ` 无法找到信号或插槽,或者参数不匹配,则连接无效。

[noexcept] QMetaObject::Connection &Connection::operator=(QMetaObject::Connection &&other)

该操作将other 按值赋值给该对象,并返回一个引用。

QMetaObject::Connection &Connection::operator=(const QMetaObject::Connection &other)

将other 分配给此连接,并返回对此连接的引用。

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