Why can't I access the elements of the container?

61 Views Asked by At

Why can't I access the elements of the container?

    void func(QList<int> &&list)
    {
        //Error 'class QForeachContainer<QList<int>&&>' has no member named 'i' _container_.control && _container_.i != _container_.e;
        foreach (int item, list) 
        {
            qDebug()<<"+++ ";
        }
    }
1

There are 1 best solutions below

0
ArashV On

QList::iterator allows you to iterate over a QList (or QQueue) and to modify the list item associated with the iterator. More info: https://doc.qt.io/qt-5/qlist-iterator.html#details

QList<int>::iterator i;
for (i = list.begin(); i != list.end(); ++i)
    qDebug() << *i << Qt::endl;