[Qt-interest] QList<T*>::iterator

Tim Dewhirst tim at bugless.co.uk
Fri May 15 11:12:59 CEST 2009


Hello,

Norbert Bokor wrote:
> I have a template class which has a QList<T*> variable. I want to use an 
> iterator for this list, but it doesn't work, the compiler says:
> 
> In file included from 
> src/test.cpp:7:                                                                                                
> 
> src/propertylist.h: In member function 
> 'PropertyList<T>::push(T*)':                                                  
> 
> src/propertylist.h:130: error: expected `;' before 
> 'p_before'                                                                        
> 
> src/propertylist.h:132: error: 'p_before' was not declared in this 
> scope          
> 
> 
> that part of the code:
> 
> template <class T>
> bool PropertyList<T>::push(T *item)
> {
>     QList<T * >::iterator p_before;   // this is line 130
> 
> What's wrong with this? If i write QList<int>::iterator for example, the 
> compiler accepts it.

This looks like you need to tell the compiler that QList< T* >::iterator 
is actually a type by adding:

typename QList< T* >::iterator p_before;

AFAICR it's because QList< T* >::iterator is a qualified dependent type. 
Disclaimer: I'm still on my first cup of coffee.

Tim



More information about the Qt-interest-old mailing list