本页内容

QQuickImageResponse Class

QQuickImageResponse 类为QQuickAsyncImageProvider 中的异步图像加载提供了接口。更多内容...

头文件: #include <QQuickImageResponse>
CMake: find_package(Qt6 REQUIRED COMPONENTS Quick)
target_link_libraries(mytarget PRIVATE Qt6::Quick)
qmake: QT += quick
继承自: QObject

公共函数

QQuickImageResponse()
virtual ~QQuickImageResponse() override
virtual QString errorString() const
virtual QQuickTextureFactory *textureFactory() const = 0

公共槽

virtual void cancel()

信号

void finished()

详细说明

图像响应的目的是为图像提供程序作业提供一种异步执行的方式。

一旦发出finished()信号,响应将通过deleteLater 被删除。如果您将QRunnable 作为QQuickImageResponse的基类,请确保禁用自动删除功能。

请参阅“图像响应提供者示例”以了解完整的实现。

另请参阅 QQuickImageProvider 。

成员函数文档

QQuickImageResponse::QQuickImageResponse()

构建图像响应

[override virtual noexcept] QQuickImageResponse::~QQuickImageResponse()

销毁图像响应

[virtual slot] void QQuickImageResponse::cancel()

此方法用于通知引擎不再需要该响应。

该方法可被重写以在提供方取消请求,但这并非强制要求。

被取消的QQuickImageResponse 仍需发出finished(),以便引擎清理QQuickImageResponse 。

注意: 无论是否调用了cancel(),都应在响应完成之前不要发出finished()。如果过早调用,引擎可能会在响应仍处于活动状态时将其销毁,从而导致崩溃。

[virtual] QString QQuickImageResponse::errorString() const

返回作业执行的错误字符串。空字符串表示没有错误。

[signal] void QQuickImageResponse::finished()

表示作业执行已完成(无论是成功完成、发生错误还是被取消)。

注意:发出 此信号必须是响应执行的最后一步操作:一旦接收到该信号,引擎将随后销毁该响应。

[pure virtual] QQuickTextureFactory *QQuickImageResponse::textureFactory() const

返回该作业的纹理工厂。如果您的提供程序支持 `QImage`,则可以使用 `QQuickTextureFactory::textureFactoryForImage `。引擎将接管返回的 `QQuickTextureFactory` 的所有权。

注意:此 方法仅在需要时才会被调用。例如,如果发生错误或作业被取消,该方法可能不会被调用。因此,请仅在此方法中分配QQuickTextureFactory 实例,或者确保在其他情况下将其销毁。

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