QQuickImageResponse Class

QQuickImageResponse 类为QQuickAsyncImageProvider 中的异步图片加载提供了一个接口。更多

Header: #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 实例,否则应确保将其删除。

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