diff --git a/src/dialogs/RoomSettings.cpp b/src/dialogs/RoomSettings.cpp
index df4eaeee..710c3de6 100644
--- a/src/dialogs/RoomSettings.cpp
+++ b/src/dialogs/RoomSettings.cpp
@@ -4,7 +4,6 @@
#include <QMessageBox>
#include <QPainter>
#include <QPixmap>
-#include <QSharedPointer>
#include <QShowEvent>
#include <QStyleOption>
#include <QVBoxLayout>
diff --git a/src/dialogs/RoomSettings.h b/src/dialogs/RoomSettings.h
index 192e922f..408804ba 100644
--- a/src/dialogs/RoomSettings.h
+++ b/src/dialogs/RoomSettings.h
@@ -19,9 +19,6 @@ class TextField;
class TextField;
class Toggle;
-template<class T>
-class QSharedPointer;
-
class EditModal : public QWidget
{
Q_OBJECT
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<std::vector<DeviceInfo>>();
-
- 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<Proxy>();
+ 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);
});
}
diff --git a/src/dialogs/UserProfile.h b/src/dialogs/UserProfile.h
index 9901771d..7dc1c0c8 100644
--- a/src/dialogs/UserProfile.h
+++ b/src/dialogs/UserProfile.h
@@ -17,6 +17,14 @@ struct DeviceInfo
Q_DECLARE_METATYPE(std::vector<DeviceInfo>)
+class Proxy : public QObject
+{
+ Q_OBJECT
+
+signals:
+ void done(const QString &user_id, const std::vector<DeviceInfo> &devices);
+};
+
namespace dialogs {
class DeviceItem : public QWidget
@@ -43,9 +51,6 @@ public:
protected:
void paintEvent(QPaintEvent *) override;
-signals:
- void devicesRetrieved(const QString &user_id, const std::vector<DeviceInfo> &devices);
-
private slots:
void updateDeviceList(const QString &user_id, const std::vector<DeviceInfo> &devices);
|