PDA

View Full Version : Get index of QValueListIterator



zlatko
16th February 2006, 11:25
Hi all!
So i try get index of my QValueListIterator



for (GroupList::const_iterator itGr=gl_GroupList.constBegin(); itGr!=gl_GroupList.constEnd(); ++itGr)
int m_nCurrKey = gl_GroupList.findIndex( (*itGr) );


But i have a compile error from qvaluelist.h



C:\Qt\3.3.5\include\qvaluelist.h(331): error C2678: binary '==' : no operator found which takes a left-hand operand of type 'const SGroup' (or there is no acceptable conversion)


Any suggestions?

jacek
16th February 2006, 16:23
Did you implement SGroup::operator==()?

zlatko
16th February 2006, 16:32
no...i must do it:confused:

jacek
16th February 2006, 16:37
no...i must do it:confused:
Judging from the error message, yes.

zlatko
16th February 2006, 17:39
Understand...So i can't get in other way position(index) of curent iterators item ?

jacek
16th February 2006, 17:56
Understand...So i can't get in other way position(index) of curent iterators item ?
This should work:
for( int i = 0, GroupList::const_iterator itGr = gl_GroupList.constBegin(); itGr != gl_GroupList.constEnd(); ++i, ++itGr) {
int m_nCurrKey = i;
//...
}

zlatko
16th February 2006, 18:52
No it was my first solution...Actually like this becouse yours cant be compiled



int i;
for( i = 0, GroupList::const_iterator itGr = gl_GroupList.constBegin(); itGr != gl_GroupList.constEnd(); ++i, ++itGr) {
int m_nCurrKey = i;


But the i think must be more elegant way to solve it...Now i see that its imposible:(

jacek
16th February 2006, 20:05
But the i think must be more elegant way to solve it...Now i see that its imposible:(
Either you use iterators or access your data by index. Usually there is no need to do both.

You can always do this:
const int size = gl_GroupList.size();
for( int i = 0; i < size; ++i ) {
int m_nCurrKey = i;
//...
// gl_GroupList[i]
//...
};

zlatko
17th February 2006, 11:27
Yes it can be more flexibility solution
thanks:)