Does anybody know why QT_STRICT_ITERATORS is not standard?
Regards,
Gunnar
 
 
Gesendet: Dienstag, 24. März 2015 um 11:28 Uhr
Von: "Jan Kundrát" <j...@kde.org>
An: interest@qt-project.org
Betreff: Re: [Interest] QVariantMap: constEnd() not equal to end()?
On Friday, 20 March 2015 07:25:48 CET, Aleksandr Mezin wrote:
> Table::const_iterator i(table.constFind(name));
> if (i != table.end()) {
> ...
> }

end() returns an interator, not a const_iterator. Obtaining an interator
(not a const_iterator) from a Qt container calls detach(), which means that
your QHash gets copied.

There are multiple ways to fix this:

- Be sure you call constEnd() rather than end().
- Make sure that your QHash is a const. That way, you call the
'const_iterator end() const' override, which cannot detach because your
class is a const one.
- Build your code with -DQT_STRICT_ITERATORS=1 to disable casts and
comparing of const vs. non-const iterators.

> 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?

Even though I know about the const_iterator vs. iterator, the behavior you
reported feels wrong to me.

Cheers,
Jan

--
Trojitá, a fast Qt IMAP e-mail client -- http://trojita.flaska.net/
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to