From 896fe069b6e1f0406ba483dd82480e32ffe2a5df Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Fri, 7 Sep 2018 12:24:09 +0300 Subject: Use proxy objects on lambdas instead of raw pointers When the object is destroyed the connections will be removed automatically by Qt. fixes #433 --- src/timeline/widgets/FileItem.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/timeline/widgets/FileItem.cpp') diff --git a/src/timeline/widgets/FileItem.cpp b/src/timeline/widgets/FileItem.cpp index f8d3272d..850941ae 100644 --- a/src/timeline/widgets/FileItem.cpp +++ b/src/timeline/widgets/FileItem.cpp @@ -50,8 +50,6 @@ FileItem::init() icon_.addFile(":/icons/icons/ui/arrow-pointing-down.png"); setFixedHeight(Height); - - connect(this, &FileItem::fileDownloadedCb, this, &FileItem::fileDownloaded); } FileItem::FileItem(const mtx::events::RoomEvent &event, QWidget *parent) @@ -110,19 +108,22 @@ FileItem::mousePressEvent(QMouseEvent *event) if (filenameToSave_.isEmpty()) return; + auto proxy = std::make_shared(); + connect(proxy.get(), &MediaProxy::fileDownloaded, this, &FileItem::fileDownloaded); + http::client()->download( url_.toString().toStdString(), - [this](const std::string &data, - const std::string &, - const std::string &, - mtx::http::RequestErr err) { + [proxy = std::move(proxy), url = url_](const std::string &data, + const std::string &, + const std::string &, + mtx::http::RequestErr err) { if (err) { nhlog::ui()->warn("failed to retrieve m.file content: {}", - url_.toString().toStdString()); + url.toString().toStdString()); return; } - emit fileDownloadedCb(QByteArray(data.data(), data.size())); + emit proxy->fileDownloaded(QByteArray(data.data(), data.size())); }); } else { openUrl(); -- cgit 1.5.1