• 3914阅读
  • 3回复

关于容器类的使用 [复制链接]

上一主题 下一主题
离线qscbmn
 

只看楼主 正序阅读 楼主  发表于: 2009-08-31
我在一个类的头文件中声明了一个容器类,但是在类的构造函数中初始化时出错。各位大侠帮我看看是怎么回事?
代码:
头文件:
#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'

离线qscbmn

只看该作者 3楼 发表于: 2009-09-17
多谢了
离线malonexx
只看该作者 2楼 发表于: 2009-08-31
帮顶下
离线hiti_tony
只看该作者 1楼 发表于: 2009-08-31
#include <QPen>
快速回复
限100 字节
 
上一个 下一个