声明类类型的QVector时出错

时间:2016-12-01 09:38:19

标签: c++ c++11 qt4 c++14 qt4.8

在Qt中声明类类型的QVector时出错。

错误:“不允许使用不完整的类型”

我不明白导致此错误的原因。

如果我在main.cpp中#include“storage.h”并声明类存储的Qvector它工作正常但是当我在波形类中执行相同操作时它报告错误。

我已尝试在波形类中声明存储类,但仍会出现相同的错误。

任何帮助??

的main.cpp

#include "test_subject_02.h"
#include <QtGui/QApplication>


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    TEST_SUBJECT_02 w;
    w.show();
    return a.exec();
}

test_subject_02.h

#ifndef TEST_SUBJECT_02_H
#define TEST_SUBJECT_02_H

#include <QtGui/QMainWindow>
#include "ui_test_subject_02.h"
#include"waveform.h"
#include "storage.h"


class TEST_SUBJECT_02 : public QMainWindow
{
    Q_OBJECT

public:
    TEST_SUBJECT_02(QWidget *parent = 0, Qt::WFlags flags = 0);
    waveform *wv;
    ~TEST_SUBJECT_02();

private:
    Ui::TEST_SUBJECT_02Class ui;
};

#endif // TEST_SUBJECT_02_H

test_subject_02.cpp

#include "test_subject_02.h"

TEST_SUBJECT_02::TEST_SUBJECT_02(QWidget *parent, Qt::WFlags flags)
    : QMainWindow(parent, flags)
{
    ui.setupUi(this);
    QVector<storage> ser; //works fine here
    wv->readfile("e:/testing2/result/3/abc.cur");

}

TEST_SUBJECT_02::~TEST_SUBJECT_02()
{

}

waveform.h

#ifndef WAVEFORM_H
#define WAVEFORM_H

#include "storage.h"
#include <QObject>

class waveform : public QObject
{
    Q_OBJECT


public:
    waveform(QObject *parent=0);
    void readfile(QString);

    QVector <storage> myvector ; // incomplete type is not allowed
    ~waveform();

private:

};

#endif // WAVEFORM_H

waveform.cpp

#include "waveform.h"

waveform::waveform(QObject *parent)
    : QObject(parent)
{

}

void waveform::readfile(QString file)
{  
    QVector<storage> sw; //again error incomplete type is not allowed

}

waveform::~waveform()
{

}

storage.h定义

#ifndef STORAGE_H
#define STORAGE_H

#include <QObject>

class storage : public QObject
{
    Q_OBJECT

public:
    storage(QObject *parent);
    storage();
    storage(QString,QString);
    ~storage();

private:
    QString x;
    QString y;

};

#endif // STORAGE_H

storage.cpp

#include "storage.h"

storage::storage(QObject *parent)
    : QObject(parent)
{

}

storage::storage(QString xcord,QString ycord)
{
    x=xcord;
    y=ycord;

}

storage::storage()
{

}

storage::~storage()
{

}

1 个答案:

答案 0 :(得分:3)

你需要在必要的文件中明确包含QVector(波形。相信),因为QT使用了很多前向声明,虽然它们在IDE中显示为正确的类,但它们不会编译,如果文件中没有包含正确的定义。