2016-12-01 87 views
0

在Qt中聲明QVector類類型時出錯。聲明類類型QVector時出錯

錯誤:「不完全類型是不允許的」

我不明白是什麼原因導致這個錯誤。

如果我#include「storage.h」在main.cpp中並聲明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() 
{ 

} 

回答

3

你需要明確包括QVector在必要的文件(waveform.hi認爲),因爲QT使用了大量的前向聲明,而它們在IDE中顯示爲正確的類,但如果文件中沒有包含正確的定義,它們將不會編譯。

+0

哦..那個愚蠢的錯誤。謝謝 – secretgenes