Wrong usage of QList::ConstIterator & QList::begin() ?

Christian Ehrlicher Ch.Ehrlicher at gmx.de
Sun Oct 19 12:36:12 BST 2008


Thiago Macieira schrieb:
> Albert Astals Cid wrote:
>> A Dissabte 18 Octubre 2008, Christian Ehrlicher va escriure:
>>> Hi,
>>>
>>> While trying to fix some bugs in KFile* on windows I saw some places
>>> like this:
>>>
>>> for ( QStringList::ConstIterator it = m_dirList.begin();
>>>        it != m_dirList.end() && !terminationRequested();
>>>        ++it )
>>>
>>> Imo the programmer here expects that m_dirList.detach() isn't called
>>> but this is wrong.
>>>
>>> m_dirList.begin() does a detach, returns a non-const iterator and then
>>> the iterator is converted to a const iterator (see qlist.h:214 & 238).
>>>
>>> Therefore I suggest to add QT_STRICT_ITERATORS to the kdelibs flags.
>>> Or does this maybe break BC?
>> This is not wrong, just not what the developer "really wanted" but it
>> works just fine, albeit a bit slower.
> 
> In this case.
> 
> In some cases, mixing const and non-const iterators can lead to crashes, 
> due to the container detaching in-between and pointers moving around.
> 
> QT_STRICT_ITERATORS is good for development, but not for release code.
> 
Ok, here a question for the trolls:
When I compile kdecore with -DQT_STRICT_ITERATORS I get the following 
undefined symbols:

kuitsemantics.obj : error LNK2001: Nicht aufgel÷stes externes Symbol 
""__declspec(dllimport) public: class QVector<class 
QXmlStreamAttribute>::const_iterator __thiscall QVector<class 
QXmlStreamAttribute>::end(void)const " 
(__imp_?end@?$QVector at VQXmlStreamAttribute@@@@QBE?AVconst_iterator at 1@XZ)".

kuitsemantics.obj : error LNK2001: Nicht aufgel÷stes externes Symbol 
""__declspec(dllimport) public: class QVector<class 
QXmlStreamAttribute>::const_iterator __thiscall QVector<class 
QXmlStreamAttribute>::begin(void)const " 
(__imp_?begin@?$QVector at VQXmlStreamAttribute@@@@QBE?AVconst_iterator at 1@XZ)".

It's because of line 1296 in kuitsemantics.cpp

I'm using 4.4.3 - do I have to compile qt with -DQT_STRICT_ITERATORS too 
or is this a bug? For me it looks like another problem because of the 
exported template class QVector<QXmlStreamAttribute>


Christian




More information about the kde-core-devel mailing list