fix segfault on close (again)

This commit is contained in:
RickyRister 2025-01-12 02:42:33 -08:00
parent 8218939c30
commit 79e341744a
3 changed files with 23 additions and 6 deletions

View file

@ -4,6 +4,7 @@
#include "./tab_supervisor.h" #include "./tab_supervisor.h"
#include <QApplication> #include <QApplication>
#include <QCloseEvent>
#include <QDebug> #include <QDebug>
#include <QScreen> #include <QScreen>
@ -43,6 +44,15 @@ void Tab::deleteCardInfoPopup(const QString &cardName)
} }
} }
/**
* Overrides the closeEvent in order to emit a close signal
*/
void Tab::closeEvent(QCloseEvent *event)
{
emit closed();
event->accept();
}
void Tab::closeRequest(bool /*forced*/) void Tab::closeRequest(bool /*forced*/)
{ {
close(); close();

View file

@ -13,6 +13,12 @@ class Tab : public QMainWindow
signals: signals:
void userEvent(bool globalEvent = true); void userEvent(bool globalEvent = true);
void tabTextChanged(Tab *tab, const QString &newTabText); void tabTextChanged(Tab *tab, const QString &newTabText);
/**
* Emitted when the tab is closed (because Qt doesn't provide a built-in close signal)
* This signal is emitted from this class's overridden Tab::closeEvent method.
* Make sure any subclasses that override closeEvent still emit this signal from there.
*/
void closed();
protected: protected:
TabSupervisor *tabSupervisor; TabSupervisor *tabSupervisor;
@ -23,6 +29,7 @@ protected:
protected slots: protected slots:
void showCardInfoPopup(const QPoint &pos, const QString &cardName, const QString &providerId); void showCardInfoPopup(const QPoint &pos, const QString &cardName, const QString &providerId);
void deleteCardInfoPopup(const QString &cardName); void deleteCardInfoPopup(const QString &cardName);
void closeEvent(QCloseEvent *event) override;
private: private:
QString currentCardName, currentProviderId; QString currentCardName, currentProviderId;

View file

@ -393,7 +393,7 @@ void TabSupervisor::actTabServer(bool checked)
tabServer = new TabServer(this, client); tabServer = new TabServer(this, client);
connect(tabServer, &TabServer::roomJoined, this, &TabSupervisor::addRoomTab); connect(tabServer, &TabServer::roomJoined, this, &TabSupervisor::addRoomTab);
myAddTab(tabServer); myAddTab(tabServer);
connect(tabServer, &Tab::destroyed, this, [this] { connect(tabServer, &Tab::closed, this, [this] {
tabServer = nullptr; tabServer = nullptr;
aTabServer->setChecked(false); aTabServer->setChecked(false);
}); });
@ -410,7 +410,7 @@ void TabSupervisor::actTabUserLists(bool checked)
connect(tabUserLists, &TabUserLists::userJoined, this, &TabSupervisor::processUserJoined); connect(tabUserLists, &TabUserLists::userJoined, this, &TabSupervisor::processUserJoined);
connect(tabUserLists, &TabUserLists::userLeft, this, &TabSupervisor::processUserLeft); connect(tabUserLists, &TabUserLists::userLeft, this, &TabSupervisor::processUserLeft);
myAddTab(tabUserLists); myAddTab(tabUserLists);
connect(tabUserLists, &Tab::destroyed, this, [this] { connect(tabUserLists, &Tab::closed, this, [this] {
tabUserLists = nullptr; tabUserLists = nullptr;
aTabUserLists->setChecked(false); aTabUserLists->setChecked(false);
}); });
@ -425,7 +425,7 @@ void TabSupervisor::actTabDeckStorage(bool checked)
tabDeckStorage = new TabDeckStorage(this, client); tabDeckStorage = new TabDeckStorage(this, client);
connect(tabDeckStorage, &TabDeckStorage::openDeckEditor, this, &TabSupervisor::addDeckEditorTab); connect(tabDeckStorage, &TabDeckStorage::openDeckEditor, this, &TabSupervisor::addDeckEditorTab);
myAddTab(tabDeckStorage); myAddTab(tabDeckStorage);
connect(tabDeckStorage, &Tab::destroyed, this, [this] { connect(tabDeckStorage, &Tab::closed, this, [this] {
tabDeckStorage = nullptr; tabDeckStorage = nullptr;
aTabDeckStorage->setChecked(false); aTabDeckStorage->setChecked(false);
}); });
@ -440,7 +440,7 @@ void TabSupervisor::actTabReplays(bool checked)
tabReplays = new TabReplays(this, client); tabReplays = new TabReplays(this, client);
connect(tabReplays, &TabReplays::openReplay, this, &TabSupervisor::openReplay); connect(tabReplays, &TabReplays::openReplay, this, &TabSupervisor::openReplay);
myAddTab(tabReplays); myAddTab(tabReplays);
connect(tabReplays, &Tab::destroyed, this, [this] { connect(tabReplays, &Tab::closed, this, [this] {
tabReplays = nullptr; tabReplays = nullptr;
aTabReplays->setChecked(false); aTabReplays->setChecked(false);
}); });
@ -455,7 +455,7 @@ void TabSupervisor::actTabAdmin(bool checked)
tabAdmin = new TabAdmin(this, client, (userInfo->user_level() & ServerInfo_User::IsAdmin)); tabAdmin = new TabAdmin(this, client, (userInfo->user_level() & ServerInfo_User::IsAdmin));
connect(tabAdmin, &TabAdmin::adminLockChanged, this, &TabSupervisor::adminLockChanged); connect(tabAdmin, &TabAdmin::adminLockChanged, this, &TabSupervisor::adminLockChanged);
myAddTab(tabAdmin); myAddTab(tabAdmin);
connect(tabAdmin, &Tab::destroyed, this, [this] { connect(tabAdmin, &Tab::closed, this, [this] {
tabAdmin = nullptr; tabAdmin = nullptr;
aTabAdmin->setChecked(false); aTabAdmin->setChecked(false);
}); });
@ -469,7 +469,7 @@ void TabSupervisor::actTabLog(bool checked)
if (checked && !tabLog) { if (checked && !tabLog) {
tabLog = new TabLog(this, client); tabLog = new TabLog(this, client);
myAddTab(tabLog); myAddTab(tabLog);
connect(tabLog, &Tab::destroyed, this, [this] { connect(tabLog, &Tab::closed, this, [this] {
tabLog = nullptr; tabLog = nullptr;
aTabAdmin->setChecked(false); aTabAdmin->setChecked(false);
}); });