[Interest] QVariantMap: constEnd() not equal to end()?
Harri Porten
porten at froglogic.com
Mon Mar 23 10:01:33 CET 2015
On Fri, 20 Mar 2015, Aleksandr Mezin wrote:
> Table::const_iterator i(table.constFind(name));
> if (i != table.end()) {
> ...
> }
>
> Table is a typedef for QHash<...>
>
> This code doesn't work as I expect with Qt 5.4.1 MSVC 2013.
> The "if" is never entered, even when 'name' isn't found in the table.
> But it starts to work after replacing "end()" with "constEnd()".
> So, I guess, end() isn't equal to constEnd()? Is it an intended behavior?
Let's say it's undefined behavior. end() and constEnd() could return the
same iterator. But it depends on the implementation as well as the state
(shared or detached) of the QHash instance. Better don't mix the const and
non-const iterator functions.
See
http://doc.qt.io/qt-5/containers.html#implicit-sharing-iterator-problem
(and the whole chapter) for more details.
Harri.
More information about the Interest
mailing list