From aa2f6ce77d924a0dc53325a425215a1b03e72f43 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Sat, 11 Aug 2018 13:50:56 +0300 Subject: Simplify dialog creation --- src/dialogs/UserProfile.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/dialogs/UserProfile.cpp') diff --git a/src/dialogs/UserProfile.cpp b/src/dialogs/UserProfile.cpp index c2c42ec4..df334b15 100644 --- a/src/dialogs/UserProfile.cpp +++ b/src/dialogs/UserProfile.cpp @@ -170,8 +170,6 @@ UserProfile::UserProfile(QWidget *parent) vlayout->setContentsMargins(WIDGET_MARGIN, TOP_WIDGET_MARGIN, WIDGET_MARGIN, WIDGET_MARGIN); qRegisterMetaType>(); - - connect(this, &UserProfile::devicesRetrieved, this, &UserProfile::updateDeviceList); } void @@ -227,10 +225,15 @@ UserProfile::init(const QString &userId, const QString &roomId) mtx::requests::QueryKeys req; req.device_keys[userId.toStdString()] = {}; + // A proxy object is used to emit the signal instead of the original object + // which might be destroyed by the time the http call finishes. + auto proxy = std::make_shared(); + QObject::connect(proxy.get(), &Proxy::done, this, &UserProfile::updateDeviceList); + http::client()->query_keys( req, - [user_id = userId.toStdString(), this](const mtx::responses::QueryKeys &res, - mtx::http::RequestErr err) { + [user_id = userId.toStdString(), proxy = std::move(proxy), this]( + const mtx::responses::QueryKeys &res, mtx::http::RequestErr err) { if (err) { nhlog::net()->warn("failed to query device keys: {} {}", err->matrix_error.error, @@ -264,7 +267,7 @@ UserProfile::init(const QString &userId, const QString &roomId) }); if (!deviceInfo.empty()) - emit devicesRetrieved(QString::fromStdString(user_id), deviceInfo); + emit proxy->done(QString::fromStdString(user_id), deviceInfo); }); } -- cgit 1.5.1