QListIterator constructor parameter conversion issue



  • I have a QList<LogParser*> logParsers where LogParser is a class I defined.

    When I try to create a QListIterator<LogParser*> iterator(logParsers), the compiler complains

    'QListIterator<T>::QListIterator(const QList<T> &)' : cannot convert parameter 1 from 'QList<T>' to 'const QList<T> &'

    What am I doing wrong?



  • Can you paste a snippet of relevant code?



  • Sure, but it's not very informative.

    @QListIterator<LogParser*> iterator(logParsers);
    while(iterator.hasNext()) {
    iterator.next()->start();
    }@



  • Including the logParsers declaration? :)



  • That's in the header file:
    @QList<LogParser*> logParsers;@

    and the constructor for this class has this bit to populate logParsers:
    @for(int i = 0; i < deviceCount; ++i) {
    logParsers.append(new LogParser(i));
    connect( logParsers[i], SIGNAL(deviceNotOpen()), SLOT(deviceNotOpen()));
    connect( logParsers[i], SIGNAL(setupComplete()), SLOT(startTimer()));
    }@



  • Hi kenbrot,

    this code perfectly compiles:

    @
    class LogParser
    {
    public:
    int i;
    int j;
    QList<int> m;
    void start() {}
    };

    int main(int argc, char argv[])
    {
    QList<LogParser
    > logParsers;

    QListIterator<LogParser*> iterator(logParsers);
    while(iterator.hasNext()) {
         iterator.next()->start();
    }
    
    return 0;
    

    }
    @

    Perhaps LogParser is only predefined?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.