jeudi 1 décembre 2016

Error while declaring QVector of class type

Getting error while declaring QVector of class type in Qt.

Error :"incomplete type is not allowed"

I didn't understand what causes this error.

if i #include "storage.h" in main.cpp and declare a Qvector of class storeage it works fine but when i do the same in waveform class it reports an error.

I've tried forward declaring storage class in waveform class but still getting the same error.

Any Help??

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()
{

}

Aucun commentaire:

Enregistrer un commentaire