QMutableStringListIterator的QStringList"不是类型"?

时间:2016-04-22 02:39:54

标签: c++ qt

我想要使用QMutableStringListIterator来迭代QStringList,但我在.h文件中出现错误,指出我的QStringList不是一种。为什么呢?

myClass.h

#ifndef MYCLASS_H
#define MYCLASS_H

#include <QDockWidget>
#include <QList>
#include <QStringList>
#include <QMutableStringListIterator>

namespace Ui {
class MyClass;
}

class MyClass: public QDockWidget
{
  Q_OBJECT

public:
  explicit MyClass(QWidget* parent = 0);
  void someFunc(QString message);
  ~MyClass();

private:
  Ui::Messages* ui;
  QStringList myList;
  QMutableStringListIterator iterator(myList); // it errors here. "myList is not a type"
};

#endif // MYCLASS_H

MyClass.cpp

#include "myclass.h"
#include <QString>
#include <QDebug>
#include <QCoreApplication>

MyClass::MyClass(QWidget* parent) :
  QDockWidget(parent),
  ui(new Ui::MyClass),
  iterator(myList)
{
  ui->setupUi(this);
}

MyClass::~MyClass()
{
  delete ui;
}

void MyClass::someFunc(QString message) {

  myList.append(message);
  qDebug() << myList.length();

}

1 个答案:

答案 0 :(得分:1)

我修好了。以下是.h文件的外观:

private:
  Ui::Messages* ui;
  QStringList myList;
  QMutableStringListIterator iterator; // do not give it the myList here
};