From 9cf708c5fc68515d2bb520aa6367f9f63eb491a3 Mon Sep 17 00:00:00 2001 From: ann0see <20726856+ann0see@users.noreply.github.com> Date: Mon, 14 Oct 2024 20:38:25 +0200 Subject: [PATCH] Fix crash on closing iOS chat dialog Using close() would crash due to a null pointer dereference --- src/chatdlg.cpp | 24 +++++++++++++++++++++--- src/chatdlg.h | 3 +++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/chatdlg.cpp b/src/chatdlg.cpp index 9f4b551082..4d7adcfd5c 100644 --- a/src/chatdlg.cpp +++ b/src/chatdlg.cpp @@ -61,12 +61,11 @@ CChatDlg::CChatDlg ( QWidget* parent ) : CBaseDlg ( parent, Qt::Window ) // use pMenu->addMenu ( pEditMenu ); #if defined( Q_OS_IOS ) - QAction* action = pMenu->addAction ( tr ( "&Close" ) ); - connect ( action, SIGNAL ( triggered() ), this, SLOT ( close() ) ); + QAction* closeAction = pMenu->addAction ( tr ( "&Close" ) ); #endif #if defined( ANDROID ) || defined( Q_OS_ANDROID ) - pEditMenu->addAction ( tr ( "&Close" ), this, SLOT ( close() ), QKeySequence ( Qt::CTRL + Qt::Key_W ) ); + pEditMenu->addAction ( tr ( "&Close" ), this, SLOT ( OnCloseClicked() ), QKeySequence ( Qt::CTRL + Qt::Key_W ) ); #endif // Now tell the layout about the menu @@ -78,6 +77,10 @@ CChatDlg::CChatDlg ( QWidget* parent ) : CBaseDlg ( parent, Qt::Window ) // use QObject::connect ( butSend, &QPushButton::clicked, this, &CChatDlg::OnSendText ); QObject::connect ( txvChatWindow, &QTextBrowser::anchorClicked, this, &CChatDlg::OnAnchorClicked ); + +#if defined( Q_OS_IOS ) + QObject::connect ( closeAction, &QAction::triggered, this, &CChatDlg::OnCloseClicked ); +#endif } void CChatDlg::OnLocalInputTextTextChanged ( const QString& strNewText ) @@ -149,3 +152,18 @@ void CChatDlg::OnAnchorClicked ( const QUrl& Url ) } } } + +#if defined( Q_OS_IOS ) || defined( ANDROID ) || defined( Q_OS_ANDROID ) +void CChatDlg::OnCloseClicked() +{ + // on mobile add a close button or menu entry +# if defined( Q_OS_IOS ) + // On Qt6, iOS crashes if we call close() due to unknown reasons, therefore we just hide() the dialog. A Qt bug is suspected. + // Checkout https://github.com/jamulussoftware/jamulus/pull/3413 + hide(); +# endif +# if defined( ANDROID ) || defined( Q_OS_ANDROID ) + close(); +# endif +} +#endif \ No newline at end of file diff --git a/src/chatdlg.h b/src/chatdlg.h index 5719ea3d60..39aa8c2a76 100644 --- a/src/chatdlg.h +++ b/src/chatdlg.h @@ -54,6 +54,9 @@ public slots: void OnLocalInputTextTextChanged ( const QString& strNewText ); void OnClearChatHistory(); void OnAnchorClicked ( const QUrl& Url ); +#if defined( Q_OS_IOS ) || defined( ANDROID ) || defined( Q_OS_ANDROID ) + void OnCloseClicked(); +#endif signals: void NewLocalInputText ( QString strNewText );