我想要使用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();
}
答案 0 :(得分:1)
我修好了。以下是.h
文件的外观:
private:
Ui::Messages* ui;
QStringList myList;
QMutableStringListIterator iterator; // do not give it the myList here
};