From b751eddd89a1f555ff08f2818eaec8369fbd3fd4 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Fri, 6 Dec 2024 07:19:02 +0800 Subject: [PATCH] fix: crash when startup. --- RedPandaIDE/widgets/codecompletionpopup.cpp | 12 ++++++----- RedPandaIDE/widgets/headercompletionpopup.cpp | 20 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/RedPandaIDE/widgets/codecompletionpopup.cpp b/RedPandaIDE/widgets/codecompletionpopup.cpp index aa4471d65..4379cf143 100644 --- a/RedPandaIDE/widgets/codecompletionpopup.cpp +++ b/RedPandaIDE/widgets/codecompletionpopup.cpp @@ -32,8 +32,11 @@ CodeCompletionPopup::CodeCompletionPopup(QWidget *parent) : QWidget(parent), + mListView(nullptr), mMutex() { + setWindowFlags(Qt::Popup); + mListView = new CodeCompletionListView(this); mModel=new CodeCompletionListModel(&mCompletionStatementList); mDelegate = new CodeCompletionListItemDelegate(mModel,this); @@ -57,9 +60,6 @@ CodeCompletionPopup::CodeCompletionPopup(QWidget *parent) : mHideSymbolsStartWithTwoUnderline = false; mHideSymbolsStartWithUnderline = false; - - // may trigger font change event, place it after member initialization - setWindowFlags(Qt::Popup); } CodeCompletionPopup::~CodeCompletionPopup() @@ -1262,8 +1262,10 @@ bool CodeCompletionPopup::event(QEvent *event) { bool result = QWidget::event(event); if (event->type() == QEvent::FontChange) { - mListView->setFont(font()); - mDelegate->setFont(font()); + if (mListView) { + mListView->setFont(font()); + mDelegate->setFont(font()); + } } return result; } diff --git a/RedPandaIDE/widgets/headercompletionpopup.cpp b/RedPandaIDE/widgets/headercompletionpopup.cpp index ee707719e..802917b9c 100644 --- a/RedPandaIDE/widgets/headercompletionpopup.cpp +++ b/RedPandaIDE/widgets/headercompletionpopup.cpp @@ -27,8 +27,11 @@ #include "../colorscheme.h" #include -HeaderCompletionPopup::HeaderCompletionPopup(QWidget* parent):QWidget(parent) +HeaderCompletionPopup::HeaderCompletionPopup(QWidget* parent):QWidget{parent}, + mListView{nullptr} { + setWindowFlags(Qt::Popup); + mListView = new CodeCompletionListView(this); mModel=new HeaderCompletionListModel(&mCompletionList, 0); QItemSelectionModel *m=mListView->selectionModel(); @@ -46,9 +49,6 @@ HeaderCompletionPopup::HeaderCompletionPopup(QWidget* parent):QWidget(parent) mCurrentFile = ""; mPhrase = ""; mIgnoreCase = false; - - // may trigger font change event, place it after member initialization - setWindowFlags(Qt::Popup); } HeaderCompletionPopup::~HeaderCompletionPopup() @@ -320,13 +320,11 @@ void HeaderCompletionPopup::hideEvent(QHideEvent *) bool HeaderCompletionPopup::event(QEvent *event) { bool result = QWidget::event(event); - switch (event->type()) { - case QEvent::FontChange: - mListView->setFont(font()); - mDelegate->setFont(font()); - break; - default: - break; + if (event->type() == QEvent::FontChange) { + if (mListView) { + mListView->setFont(font()); + mDelegate->setFont(font()); + } } return result; }