QmlDesigner: Fix potential crash

Change-Id: I85e5b7d8f03e270540294a20ccc24658943a2c9b
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Thomas Hartmann
2022-05-31 17:59:23 +02:00
parent ffe94d177c
commit 57cb9d888b

View File

@@ -207,10 +207,11 @@ void ItemLibraryCategoriesModel::clearSelectedCategory(int categoryIndex)
QPointer<ItemLibraryCategory> ItemLibraryCategoriesModel::selectCategory(int categoryIndex)
{
if (categoryIndex == -1 || m_categoryList.isEmpty())
if (m_categoryList.isEmpty() || categoryIndex < 0 || categoryIndex >= m_categoryList.size())
return nullptr;
const QPointer<ItemLibraryCategory> category = m_categoryList.at(categoryIndex);
if (!category->categorySelected()) {
category->setCategorySelected(true);
emit dataChanged(index(categoryIndex),index(categoryIndex), {m_roleNames.key("categorySelected")});