Fix: lrcompletermodel access to null ptr

This commit is contained in:
Dmitry Zagorodnev 2023-02-20 14:29:32 +03:00
parent 56e145ecd8
commit de850125aa
2 changed files with 11 additions and 10 deletions

View File

@ -22,16 +22,17 @@ QModelIndex CompleterModel::index(int row, int column, const QModelIndex &parent
return createIndex(row, column, parentItem->child(row)); return createIndex(row, column, parentItem->child(row));
} }
QModelIndex CompleterModel::parent(const QModelIndex &child) const QModelIndex CompleterModel::parent(const QModelIndex &child) const {
{ if(child.isValid()) {
if (child.isValid()){ if(CompleterItem *childItem = static_cast<CompleterItem *>(child.internalPointer());
CompleterItem *childItem = static_cast<CompleterItem*>(child.internalPointer()); childItem) {
CompleterItem *parentItem = childItem->parent(); CompleterItem *parentItem = childItem->parent();
if (parentItem != &m_root) { if(parentItem != &m_root) {
return indexFromItem(parentItem); return indexFromItem(parentItem);
} }
} }
return QModelIndex(); }
return QModelIndex();
} }
int CompleterModel::rowCount(const QModelIndex &parent) const int CompleterModel::rowCount(const QModelIndex &parent) const

View File

@ -35,7 +35,7 @@ public:
void appendRow(CompleterItem* child); void appendRow(CompleterItem* child);
void appendRows(const QList<CompleterItem *> &children); void appendRows(const QList<CompleterItem *> &children);
private: private:
CompleterItem* m_parent; CompleterItem* m_parent{nullptr};
QVector<QSharedPointer<CompleterItem> > m_children; QVector<QSharedPointer<CompleterItem> > m_children;
QString m_text; QString m_text;
QIcon m_icon; QIcon m_icon;