Results 1 to 9 of 9

Thread: Get index of QValueListIterator

  1. #1
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Get index of QValueListIterator

    Hi all!
    So i try get index of my QValueListIterator

    Qt Code:
    1. for (GroupList::const_iterator itGr=gl_GroupList.constBegin(); itGr!=gl_GroupList.constEnd(); ++itGr)
    2. int m_nCurrKey = gl_GroupList.findIndex( (*itGr) );
    To copy to clipboard, switch view to plain text mode 

    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?
    a life without programming is like an empty bottle

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Get index of QValueListIterator

    Did you implement SGroup::operator==()?

  3. #3
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Get index of QValueListIterator

    no...i must do it
    a life without programming is like an empty bottle

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Get index of QValueListIterator

    Quote Originally Posted by zlatko
    no...i must do it
    Judging from the error message, yes.

  5. #5
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Get index of QValueListIterator

    Understand...So i can't get in other way position(index) of curent iterators item ?
    a life without programming is like an empty bottle

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Get index of QValueListIterator

    Quote Originally Posted by zlatko
    Understand...So i can't get in other way position(index) of curent iterators item ?
    This should work:
    Qt Code:
    1. for( int i = 0, GroupList::const_iterator itGr = gl_GroupList.constBegin(); itGr != gl_GroupList.constEnd(); ++i, ++itGr) {
    2. int m_nCurrKey = i;
    3. //...
    4. }
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Get index of QValueListIterator

    No it was my first solution...Actually like this becouse yours cant be compiled

    Qt Code:
    1. int i;
    2. for( i = 0, GroupList::const_iterator itGr = gl_GroupList.constBegin(); itGr != gl_GroupList.constEnd(); ++i, ++itGr) {
    3. int m_nCurrKey = i;
    To copy to clipboard, switch view to plain text mode 

    But the i think must be more elegant way to solve it...Now i see that its imposible
    a life without programming is like an empty bottle

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Get index of QValueListIterator

    Quote Originally Posted by zlatko
    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:
    Qt Code:
    1. const int size = gl_GroupList.size();
    2. for( int i = 0; i < size; ++i ) {
    3. int m_nCurrKey = i;
    4. //...
    5. // gl_GroupList[i]
    6. //...
    7. };
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Get index of QValueListIterator

    Yes it can be more flexibility solution
    thanks
    a life without programming is like an empty bottle

Similar Threads

  1. QTreView::isExpanded ( index ) allways false ?
    By jpujolf in forum Qt Programming
    Replies: 3
    Last Post: 24th September 2010, 10:23
  2. Replies: 3
    Last Post: 25th July 2008, 14:30
  3. QProcess readStdOut index
    By user_mail07 in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2008, 19:37
  4. Qtopia core 4.2.2 cross compile make error
    By smiyai18 in forum Installation and Deployment
    Replies: 2
    Last Post: 28th August 2007, 17:04
  5. Qt and MySQL Database Connection
    By shamik in forum Qt Programming
    Replies: 41
    Last Post: 6th October 2006, 12:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.