forked from qt-creator/qt-creator
Fix crash when widget was not created
We only create the actions in case the widget is actually created. m_projectModel and m_sessionModel are intialized as part of the SessionsPage widget. Task-numnber: QDS-6332 Change-Id: Ib127de69ca4057c229bf977c012e5cd2b2a53f0d Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -124,28 +124,6 @@ void ProjectModel::resetProjects()
|
||||
|
||||
ProjectWelcomePage::ProjectWelcomePage()
|
||||
{
|
||||
const int actionsCount = 9;
|
||||
Context welcomeContext(Core::Constants::C_WELCOME_MODE);
|
||||
|
||||
const Id projectBase = PROJECT_BASE_ID;
|
||||
const Id sessionBase = SESSION_BASE_ID;
|
||||
for (int i = 1; i <= actionsCount; ++i) {
|
||||
auto act = new QAction(tr("Open Session #%1").arg(i), this);
|
||||
Command *cmd = ActionManager::registerAction(act, sessionBase.withSuffix(i), welcomeContext);
|
||||
cmd->setDefaultKeySequence(QKeySequence((useMacShortcuts ? tr("Ctrl+Meta+%1") : tr("Ctrl+Alt+%1")).arg(i)));
|
||||
connect(act, &QAction::triggered, this, [this, i] {
|
||||
if (i <= m_sessionModel->rowCount())
|
||||
openSessionAt(i - 1);
|
||||
});
|
||||
|
||||
act = new QAction(tr("Open Recent Project #%1").arg(i), this);
|
||||
cmd = ActionManager::registerAction(act, projectBase.withSuffix(i), welcomeContext);
|
||||
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+%1").arg(i)));
|
||||
connect(act, &QAction::triggered, this, [this, i] {
|
||||
if (i <= m_projectModel->rowCount(QModelIndex()))
|
||||
openProjectAt(i - 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Utils::Id ProjectWelcomePage::id() const
|
||||
@@ -185,6 +163,40 @@ void ProjectWelcomePage::openProjectAt(int index)
|
||||
ProjectExplorerPlugin::openProjectWelcomePage(projectFile);
|
||||
}
|
||||
|
||||
void ProjectWelcomePage::createActions()
|
||||
{
|
||||
static bool actionsRegistered = false;
|
||||
|
||||
if (actionsRegistered)
|
||||
return;
|
||||
|
||||
actionsRegistered = true;
|
||||
|
||||
const int actionsCount = 9;
|
||||
Context welcomeContext(Core::Constants::C_WELCOME_MODE);
|
||||
|
||||
const Id projectBase = PROJECT_BASE_ID;
|
||||
const Id sessionBase = SESSION_BASE_ID;
|
||||
|
||||
for (int i = 1; i <= actionsCount; ++i) {
|
||||
auto act = new QAction(tr("Open Session #%1").arg(i), this);
|
||||
Command *cmd = ActionManager::registerAction(act, sessionBase.withSuffix(i), welcomeContext);
|
||||
cmd->setDefaultKeySequence(QKeySequence((useMacShortcuts ? tr("Ctrl+Meta+%1") : tr("Ctrl+Alt+%1")).arg(i)));
|
||||
connect(act, &QAction::triggered, this, [this, i] {
|
||||
if (i <= m_sessionModel->rowCount())
|
||||
openSessionAt(i - 1);
|
||||
});
|
||||
|
||||
act = new QAction(tr("Open Recent Project #%1").arg(i), this);
|
||||
cmd = ActionManager::registerAction(act, projectBase.withSuffix(i), welcomeContext);
|
||||
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+%1").arg(i)));
|
||||
connect(act, &QAction::triggered, this, [this, i] {
|
||||
if (i <= m_projectModel->rowCount(QModelIndex()))
|
||||
openProjectAt(i - 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////
|
||||
|
||||
static QColor themeColor(Theme::Color role)
|
||||
@@ -636,7 +648,11 @@ public:
|
||||
|
||||
QWidget *ProjectWelcomePage::createWidget() const
|
||||
{
|
||||
return new SessionsPage(const_cast<ProjectWelcomePage *>(this));
|
||||
auto that = const_cast<ProjectWelcomePage *>(this);
|
||||
QWidget *widget = new SessionsPage(that);
|
||||
that->createActions();
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -75,6 +75,7 @@ signals:
|
||||
private:
|
||||
void openSessionAt(int index);
|
||||
void openProjectAt(int index);
|
||||
void createActions();
|
||||
|
||||
friend class SessionsPage;
|
||||
SessionModel *m_sessionModel = nullptr;
|
||||
|
Reference in New Issue
Block a user