Skip to content

Commit

Permalink
Dont' return a const ref to QModelIndex
Browse files Browse the repository at this point in the history
The conversion operator from QPMI to QModelIndex should return by
value, to hide implementation details and so that we don't have to
rely on a static empty QModelIndex.

Change-Id: I92b3f8451422f2b69bf31f28b387a124fd24ec46
Reviewed-by: Giuseppe D'Angelo <[email protected]>
(cherry picked from commit 0cd2935)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
  • Loading branch information
laknoll authored and Qt Cherry-pick Bot committed Dec 4, 2020
1 parent 6012285 commit 57e9d9e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/corelib/itemmodels/qabstractitemmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,17 +488,16 @@ QPersistentModelIndex &QPersistentModelIndex::operator=(const QModelIndex &other
}

/*!
\fn QPersistentModelIndex::operator const QModelIndex&() const
\fn QPersistentModelIndex::operator QModelIndex() const
Cast operator that returns a const QModelIndex&.
Cast operator that returns a QModelIndex.
*/

QPersistentModelIndex::operator const QModelIndex&() const
QPersistentModelIndex::operator QModelIndex() const
{
static const QModelIndex invalid;
if (d)
return d->index;
return invalid;
return QModelIndex();
}

/*!
Expand Down
2 changes: 1 addition & 1 deletion src/corelib/itemmodels/qabstractitemmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class Q_CORE_EXPORT QPersistentModelIndex
bool operator==(const QModelIndex &other) const;
bool operator!=(const QModelIndex &other) const;
QPersistentModelIndex &operator=(const QModelIndex &other);
operator const QModelIndex&() const;
operator QModelIndex() const;
int row() const;
int column() const;
void *internalPointer() const;
Expand Down

0 comments on commit 57e9d9e

Please sign in to comment.