我在一个类的头文件中声明了一个容器类,但是在类的构造函数中初始化时出错。各位大侠帮我看看是怎么回事?
代码:
头文件:
#ifndef PLOTTER_H
#define PLOTTER_H
#include <QMap>
#include <QPixmap>
#include <QVector>
#include <QWidget>
#include <QLabel>
#include <QComboBox>
#include <QStringList>
static const QColor colorForIds[6] = {
Qt::red, Qt::green, Qt::blue, Qt::cyan, Qt::magenta, Qt::yellow
};
class Plotter : public QWidget
{
Q_OBJECT
……
……
QVector<QPen> curPen;
}
源文件:
#include <QtGui>
#include <cmath>
#include "plotter.h"
Plotter::Plotter(QWidget *parent)
: QWidget(parent)
{
……
for(int i = 0; i < 6; i++)
curPen.append(QPen(colorForIds, i, Qt::SolidLine, Qt::RoundCap));
……
}
错误信息:
c:/Qt/2009.03/qt/include/QtCore/../../src/corelib/tools/qvector.h:114: instantiated from `QVector<T>::~QVector() [with T = QPen]'
D:/Backup/MyDocuments/QtProjects/chap05/plotter1/debug/moc_plotter.cpp:77: instantiated from here
c:/Qt/2009.03/qt/include/QtCore/../../src/corelib/tools/qvector.h:98: error: `QVectorTypedData<T>::array' has incomplete type
c:/Qt/2009.03/qt/include/QtGui/../../src/gui/kernel/qwindowdefs.h:73: error: forward declaration of `struct QPen'
c:/Qt/2009.03/qt/include/QtCore/../../src/corelib/tools/qvector.h:419: instantiated from `void QVector<T>::free(QVectorTypedData<T>*) [with T = QPen]'
c:/Qt/2009.03/qt/include/QtCore/../../src/corelib/tools/qvector.h:114: instantiated from `QVector<T>::~QVector() [with T = QPen]'
D:/Backup/MyDocuments/QtProjects/chap05/plotter1/debug/moc_plotter.cpp:77: instantiated from here
c:/Qt/2009.03/qt/include/QtCore/../../src/corelib/global/qglobal.h:1778: error: invalid application of `sizeof' to incomplete type `QPen'
c:/Qt/2009.03/qt/include/QtCore/../../src/corelib/tools/qvector.h:114: instantiated from `QVector<T>::~QVector() [with T = QPen]'
D:/Backup/MyDocuments/QtProjects/chap05/plotter1/debug/moc_plotter.cpp:77: instantiated from here
c:/Qt/2009.03/qt/include/QtCore/../../src/corelib/tools/qvector.h:420: error: 'struct QVectorTypedData<QPen>' has no member named 'array'
c:/Qt/2009.03/qt/include/QtCore/../../src/corelib/tools/qvector.h:421: error: invalid use of undefined type `struct QPen'
c:/Qt/2009.03/qt/include/QtGui/../../src/gui/kernel/qwindowdefs.h:73: error: forward declaration of `struct QPen'
c:/Qt/2009.03/qt/include/QtCore/../../src/corelib/tools/qvector.h:422: error: cannot decrement a pointer to incomplete type `QPen'
c:/Qt/2009.03/qt/include/QtCore/../../src/corelib/tools/qvector.h:423: error: invalid use of undefined type `struct QPen'
c:/Qt/2009.03/qt/include/QtGui/../../src/gui/kernel/qwindowdefs.h:73: error: forward declaration of `struct QPen'