Qt: VectorIterator qt is not type

261 Views Asked by At

I need to create a QVectorIterator to iterate a QVector of QStrings as follows:

#include <QString>
#include <QVectorIterator>

#include <QLabel>
#include <QTimer>

class Dice : public QLabel
{
    Q_OBJECT

    private:
        QVector<QString> dice_faces;
        QVectorIterator<QString> it( dice_faces );
        QTimer *timer;
    ...

But I get this error, and don't understand what is wrong, or did QVectorIterator can't iterate over QString vector?

Dice.h:16: error: 'dice_faces' is not a type
     QVectorIterator<QString> i( dice_faces );
                                 ^
1

There are 1 best solutions below

2
On BEST ANSWER

You need to initialize the iterator in the initializer list in the constructor

#include <QString>
#include <QVectorIterator>

#include <QLabel>
#include <QTimer>

class Dice : public QLabel
{
    Q_OBJECT

    public:
        Dice(QObject *parent);

    private:
        QVector<QString> dice_faces;
        QVectorIterator<QString> it( dice_faces );
        QTimer *timer;
    // ...

dice.cpp

// ...

Dice::Dice(QObject *parent)
  : QLabel(parent),
    it(dice_faces)
{
}