Fix use after free from Qml widget

This commit is contained in:
Nicolas Werner 2021-05-30 00:23:57 +02:00
parent 2174f6507f
commit 18ff58edb3
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
3 changed files with 13 additions and 3 deletions

View file

@ -171,6 +171,14 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent)
activateWindow(); activateWindow();
}); });
connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this, [this]() {
// ensure the qml context is shutdown before we destroy all other singletons
// Otherwise Qml will try to access the room list or settings, after they have been
// destroyed
topLayout_->removeWidget(view_manager_->getWidget());
delete view_manager_->getWidget();
});
connect( connect(
this, this,
&ChatPage::initializeViews, &ChatPage::initializeViews,

View file

@ -13,7 +13,8 @@
#include "UserSettingsPage.h" #include "UserSettingsPage.h"
RoomlistModel::RoomlistModel(TimelineViewManager *parent) RoomlistModel::RoomlistModel(TimelineViewManager *parent)
: manager(parent) : QAbstractListModel(parent)
, manager(parent)
{ {
connect(ChatPage::instance(), &ChatPage::decryptSidebarChanged, this, [this]() { connect(ChatPage::instance(), &ChatPage::decryptSidebarChanged, this, [this]() {
auto decrypt = ChatPage::instance()->userSettings()->decryptSidebar(); auto decrypt = ChatPage::instance()->userSettings()->decryptSidebar();

View file

@ -129,7 +129,8 @@ TimelineViewManager::userStatus(QString id) const
} }
TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *parent) TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *parent)
: imgProvider(new MxcImageProvider()) : QObject(parent)
, imgProvider(new MxcImageProvider())
, colorImgProvider(new ColorImageProvider()) , colorImgProvider(new ColorImageProvider())
, blurhashProvider(new BlurhashProvider()) , blurhashProvider(new BlurhashProvider())
, callManager_(callManager) , callManager_(callManager)
@ -230,7 +231,7 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par
"Error: Only enums"); "Error: Only enums");
#ifdef USE_QUICK_VIEW #ifdef USE_QUICK_VIEW
view = new QQuickView(); view = new QQuickView(parent);
container = QWidget::createWindowContainer(view, parent); container = QWidget::createWindowContainer(view, parent);
#else #else
view = new QQuickWidget(parent); view = new QQuickWidget(parent);