QXmppHttpUploadManager Class
| Header: | #include <QXmppHttpUploadManager> |
| Since: | QXmpp 1.5 |
| Inherits: | QXmppClientExtension |
- List of all members, including inherited members
- QXmppHttpUploadManager is part of Managers.
Properties
(since QXmpp 1.13)services : const QVector<QXmppHttpUploadService>(since QXmpp 1.13)support : const QXmppHttpUploadManager::Support
Public Functions
| QXmppHttpUploadManager() | |
| QXmppHttpUploadManager(QNetworkAccessManager *netManager) | |
(since QXmpp 1.13) QVector<QXmppHttpUploadService> | services() const |
(since QXmpp 1.13) QXmppHttpUploadManager::Support | support() const |
| std::shared_ptr<QXmppHttpUpload> | uploadFile(const QFileInfo &fileInfo, const QString &filename = {}, const QString &uploadServiceJid = {}) |
| std::shared_ptr<QXmppHttpUpload> | uploadFile(std::unique_ptr<QIODevice> data, const QString &filename, const QMimeType &mimeType, qint64 fileSize = -1, const QString &uploadServiceJid = {}) |
Signals
| void | servicesChanged() |
| void | supportChanged() |
Detailed Description
The upload manager allows to upload a file to a server via XEP-0363: HTTP File Upload. This can be used for sending files to other users.
QXmppHttpUploadManager depends on QXmppDiscoveryManager.
Property Documentation
[read-only, since QXmpp 1.13] services : const QVector<QXmppHttpUploadService>
This property was introduced in QXmpp 1.13.
Access functions:
| QVector<QXmppHttpUploadService> | services() const |
Notifier signal:
| void | servicesChanged() |
See also QXmppHttpUploadManager::services().
[read-only, since QXmpp 1.13] support : const QXmppHttpUploadManager::Support
This property was introduced in QXmpp 1.13.
Access functions:
| QXmppHttpUploadManager::Support | support() const |
Notifier signal:
| void | supportChanged() |
See also QXmppHttpUploadManager::support().
Member Function Documentation
QXmppHttpUploadManager::QXmppHttpUploadManager()
Constructor
Creates and uses a new network access manager.
[explicit] QXmppHttpUploadManager::QXmppHttpUploadManager(QNetworkAccessManager *netManager)
Constructor
netManager is a shared network access manager, which needs to have at least the lifetime of this manager.
[since QXmpp 1.13] QVector<QXmppHttpUploadService> QXmppHttpUploadManager::services() const
Returns all discovered HTTP File Upload services.
Note: Getter function for property services.
This function was introduced in QXmpp 1.13.
[signal] void QXmppHttpUploadManager::servicesChanged()
Emitted when services have changed.
Note: Notifier signal for property services.
[since QXmpp 1.13] QXmppHttpUploadManager::Support QXmppHttpUploadManager::support() const
Returns the server's support for upload services.
Note: Getter function for property support.
This function was introduced in QXmpp 1.13.
[signal] void QXmppHttpUploadManager::supportChanged()
Emitted when support has changed.
Note: Notifier signal for property support.
std::shared_ptr<QXmppHttpUpload> QXmppHttpUploadManager::uploadFile(const QFileInfo &fileInfo, const QString &filename = {}, const QString &uploadServiceJid = {})
Upload data from a local file.
fileInfo is a QFileInfo about a local file. filename specifies how the file on the server should be called. This is commonly used as last part of the resulting url. uploadServiceJid optionally specifies the jid from which an upload url can be requested (upload service).
Returns an object representing the ongoing upload. The object is passed as a shared_ptr, which means it will be stored as long as there is a reference to it. While this avoids errors from accessing it after it was deleted, you should try not store it unneccesarily long to keep the memory usage down. You can for example use std::weak_ptr to not increase the lifetime, for example when capturing in long living lambdas, for example in connects. You should also make sure to use the 4-arg QObject::connect, so the connection and the connected lambda can be deleted after the upload finished.
std::weak_ptr<QXmppHttpUpload> uploadPtr = upload; connect(upload.get(), &QXmppHttpUpload::progressChanged, this, [uploadPtr]() { auto upload = uploadPtr.lock(); if (upload) { qDebug() << upload->progress(); } });
std::shared_ptr<QXmppHttpUpload> QXmppHttpUploadManager::uploadFile(std::unique_ptr<QIODevice> data, const QString &filename, const QMimeType &mimeType, qint64 fileSize = -1, const QString &uploadServiceJid = {})
Uploads the data from a QIODevice.
data is the QIODevice to read the data from. This can for example be a QFile. It can be sequential or non-sequential. filename specifies how the file on the server should be called. This is commonly used as last part of the resulting url. fileSize is the size of the file, in bytes. If negative the size from the IO device is used. mimeType is the mime type of the file. uploadServiceJid optionally specifies the jid from which an upload url can be requested (upload service).
Returns an object representing the ongoing upload. The object is passed as a shared_ptr, which means it will be stored as long as there is a reference to it. While this avoids errors from accessing it after it was deleted, you should try not store it unneccesarily long to keep the memory usage down. You can for example use std::weak_ptr to not increase the lifetime, for example when capturing in long living lambdas, for example in connects. You should also make sure to use the 4-arg QObject::connect, so the connection and the connected lambda can be deleted after the upload finished.
std::weak_ptr<QXmppHttpUpload> uploadPtr = upload; connect(upload.get(), &QXmppHttpUpload::progressChanged, this, [uploadPtr]() { auto upload = uploadPtr.lock(); if (upload) { qDebug() << upload->progress(); } });